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
曾经蜡笔没有小新2017-05-19 10:23:40
React has its life cycle, this.state will change in the next cycle, not this cycle.
伊谢尔伦2017-05-19 10:23:40
setState()
is asynchronous!
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.