I change the state value in react. First, the view has been rendered, but after changing the value, the display is still the original value
Thanks
欢迎选择我的课程,让我们一起见证您的进步~~
http://stackoverflow.com/a/36...
React has its life cycle, this.state will change in the next cycle, not this cycle.
setState() is asynchronous!
setState()
If you want to see the updated state, you have to use callback:
setState(new_state, () => { console.log(this.state); });
Also, if multiple setState() are called together, it may accumulate to refresh the page once.
http://stackoverflow.com/a/36...
React has its life cycle, this.state will change in the next cycle, not this cycle.
setState()
is asynchronous!If you want to see the updated state, you have to use callback:
Also, if multiple setState() are called together, it may accumulate to refresh the page once.