Intermediate React Interview QuestionsIntermediateConcept
React · Question 33
How does React batch state updates, and why does it matter?
Direct answer
React queues state updates during an event and processes them together before the next render, reducing unnecessary intermediate renders and keeping each render internally consistent.
Calling a state setter does not immediately mutate the state variable from the current render. React queues the update and normally processes the queued work after the event handler has finished.
- Performance: several related updates can be handled in one render instead of producing a partially updated UI after every setter call.
- Snapshot behavior: code still sees the state values captured by the render that created the current event handler.
- Intentional events: separate user interactions such as separate clicks are handled independently rather than being merged into one logical event.