React 18 (in alpha at this time) introduces **Automatic Batching**. Previously, React only batched state updates inside event handlers. Now it batches everywhere—setTimeout, Promises, native events.
Before React 18
// Two re-renders!
setTimeout(() => {
setCount(c => c + 1);
setFlag(f => !f);
}, 1000);
After React 18
// One re-render (batched!)
setTimeout(() => {
setCount(c => c + 1);
setFlag(f => !f);
}, 1000);
Key Takeaways
- Use `flushSync` if you explicitly need an immediate render.
- This reduces rendering overhead significantly in complex apps.
Discover more from C4: Container, Code, Cloud & Context
Subscribe to get the latest posts sent to your email.