Why calling setState method doesn't mutate the state immediately?

前端 未结 3 829
面向向阳花
面向向阳花 2020-11-21 15:22

Ok, i\'ll try and make this quick because it SHOULD be an easy fix...

I\'ve read a bunch of similar questions, and the answer seems to be quite obvious. Nothing I wo

3条回答
  •  耶瑟儿~
    2020-11-21 16:20

    This is by-design due to performance considerations. setState in React is a function guaranteed to re-render Component, which is a costly CPU process. As such, its designers wanted to optimize by gathering multiple rendering actions into one, hence setState is asynchronous.

提交回复
热议问题