javascript - react state change problem
天蓬老师
天蓬老师 2017-05-19 10:21:40
0
3
434

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

天蓬老师
天蓬老师

欢迎选择我的课程,让我们一起见证您的进步~~

reply all(3)
为情所困

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:

setState(new_state, () => {
   console.log(this.state);
});

Also, if multiple setState() are called together, it may accumulate to refresh the page once.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template