react - An update (setState, replaceState, or forceUpdate) was scheduled from inside an update function. Update functions should be pure, with zero side-effects
2018-11-02T11:14:38Z||2018-11-02T11:14:38Z
Warning: An update (setState, replaceState, or forceUpdate) was scheduled from inside an update function. Update functions should be pure, with zero side-effects. Consider using componentDidUpdate or a callback.
问题出在你在用this.setState
的callback的方式,但是在callback里你由调用了setState
, 比如:
this.setState((prevState) => {
// ...
this.setState({ a: aaa })
})
所以应该返回新的state:
this.setState((prevState) => {
// ...
return { a: aaa }
})