When value is assigned to components state, why console.log prints the previous state?

后端 未结 5 1362
死守一世寂寞
死守一世寂寞 2020-11-30 09:26

I\'m sending values of numbers from Numbers component to Main component. Everything is working fine until I set that value in my Main component to that component\'s state.<

5条回答
  •  孤城傲影
    2020-11-30 09:50

    In the docs of the setState function is an interesting note:

    setState() does not immediately mutate this.state but creates a pending state transition. Accessing this.state after calling this method can potentially return the existing value.

    https://facebook.github.io/react/docs/component-api.html

提交回复
热议问题