Skip to main content

What happens when two state updates occur in one event handler?

Mid React
Quick Answer React 18 batches all state updates in one event handler into a single re-render. So setName('Alice'); setAge(30); triggers one render, not two. React collects all updates from the handler, applies them all, then renders once with the final state. This is automatic in React 18 รขโ‚ฌโ€ no unstable_batchedUpdates needed.

Answer

React batches them into a single render for better performance.
S
SugharaIQ Editorial Team Verified Answer

This answer has been peer-reviewed by industry experts holding senior engineering roles to ensure technical accuracy and relevance for modern interview standards.

Want to bookmark, take notes, or join discussions?

Sign in to access all features and personalize your learning experience.

Sign In Create Account

Source: SugharaIQ

Ready to level up? Start Practice