Answer
Batching groups multiple setState calls into a single re-render for performance.
- React 17: batched only inside React event handlers.
- React 18: automatic batching everywhere — promises,
setTimeout, native event listeners, fetch callbacks.
Opt out with flushSync when you need the DOM updated immediately (e.g. measuring layout after state change).