Why doesn’t React update this.state synchronously?

Posted by Prem Tiwari | Updated on

As explained in the previous section, React intentionally “waits” until all components call setState() in their event handlers before starting to re-render. This boosts performance by avoiding unnecessary re-renders.

However, you might still be wondering why React doesn’t just update this.state immediately without re-rendering.

There are two main reasons:

  • This would break the consistency between props and state, causing issues that are very hard to debug.
  • This would make some of the new features we’re working on impossible to implement.

This GitHub comment dives deep into the specific examples.


If you like this question & answer and want to contribute, then write your question & answer and email to freewebmentor[@]gmail.com. Your question and answer will appear on FreeWebMentor.com and help other developers.

Related Questions & Answers