react warning cannot set state when using promises

前端 未结 7 1343
情深已故
情深已故 2020-12-19 13:40

I\'m trying to query the server to get list of nav items so I can build my menu on init. I\'ve so far managed to create a static page with 3 contents on the home page, which

7条回答
  •  被撕碎了的回忆
    2020-12-19 14:23

    I would move the logic of your get request into componentWillMount. The React error is telling you that the promise can only be called in a "Mounting component". Then you can call setState. Then in your render you can conditionally render based on the state variable.

    {this.state.navList.length &&
             
    }

    You can also render a different loading component while you wait for the data to return.

提交回复
热议问题