LoginSignup
1
1

More than 5 years have passed since last update.

reactのstateはsetStateした瞬間に更新されるわけではない😭

Last updated at Posted at 2018-07-13

reactでsetStateした瞬間にstateが更新されると思われがちだが。。。(自分もそう思っていた)

実際は「renderメソッドが呼ばれて描画されるまでにはstateが更新されるようになっている」という認識に公式docを読んでから至った。


Because this.props and this.state may be updated asynchronously, you should not rely on their values for calculating the next state.

https://reactjs.org/docs/state-and-lifecycle.htmlより

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1