0
Challenge · 94React Internals
Automatic Batching
Internalsused in ~50% of apps
Fire five setStates in a click handler and React still paints the screen once — not five times. Knowing exactly when React collapses updates into a single render (and when it used to not) is what separates a junior who memorised useState from someone who understands React's render loop.
Core idea. Batching is React grouping multiple state updates that happen in the same tick into ONE re-render+commit. Since React 18 (with createRoot) this happens for updates from ANY source — events, promises, timeouts, native handlers — not just React event handlers. flushSync is the deliberate escape hatch to force a synchronous render mid-batch.
poke it, drag it,
try to break it
try to break it
no slides here.
you drive.
you drive.
Playground, this isn't a screenshot
updates fire from
React version
function handleClick() {
setCount(c => c + 1);
setFlag(f => !f);
setText("hi");
}
re-renders
?
3 setStates fired
Pick a world above, then run the three updates and predict the render count.
↑ play a little first, then dig in