Mak Ijah’s clap button calls setCount three times in one click: count + 1 or c => c + 1, directly, in a setTimeout, in a then or through flushSync, and the…
Why it matters
Misreading batching breeds "why did count only go up 1?" bugs and wrong performance assumptions. Knowing a value update from an updater function makes state updates right every time.
The key idea
Batching merges renders; what decides the result is what you queue
Common mistakes
Expecting setCount(count+1) ×3 to add up to +3 All three read this render’s count. Use the updater setCount(c => c + 1) when you need them to add up.
Reading state right after setStatesetCount(5); console.log(count) is still the old value. The new value exists in the next render; if you need it now, compute it into a variable first: const next = count + 1.
Assuming setState in a setTimeout renders three times That was React 17: outside event handlers each setState rendered on its own. Since React 18 (React 19 here) they are all batched into one render. Need a render right away? flushSync.
Try it in this playground
Click with setCount(count + 1) three times Up 1, one render: all three read the same count.
Click with setCount(c => c + 1) Up 3, still one render: each updater gets the queue’s latest value.
Move all three into a setTimeout Still one render: automatic batching since React 18.
Wrap each update in flushSync Batching is off: with c => c + 1, three renders.