componentDidMount()没有在React JS中被解雇

时间:2019-05-24 14:07:04

标签: javascript reactjs

componentDidMount没有被调用,我试图从api获取结果并根据这些结果渲染组件。 fetchquestions()将调用API,并且NavigateQuestions组件将根据API中的问题长度进行呈现。

class Status extends Component {
    constructor(props) {
        super(props);

    }
    componentDidMount() {
        const {
            surveyStore, questionnaireStore
        } = this.props;
        surveyStore.fetchQuestions();
        const {
            questions
        } = surveyStore
        console.log(questions);
        questionnaireStore.questionLength = questions.length;
        questionnaireStore.createStateForQuestions();
    }

    render() {
        const {
            classes
        } = this.props;

        return ( < div className = {
                classes.root
            } >
            < Grid container spacing = {
                16
            }
            item xs = {
                9
            }
            sm = {
                9
            } >
            < Grid item xs = {
                12
            } >
            < Paper className = {
                classes.paper
            } > {

                this.state.questions.map((result, index) => {
                    return ( < NavigateQuestions / >

                    )
                })
            }

            < /Paper> < /Grid >

            < /Grid> < /Grid > < /div>

        )
    }

}

export default withRouter(withStyles(styles)(inject("surveyStore", "questionnaireStore")(
    observer((Status)))));

我收到TypeError:

  

无法在浏览器中读取null属性'questions'。我使用mobx进行stateManagement

0 个答案:

没有答案