0
Challenge · 12React Core
State Updates
Coreused in ~100% of apps
The single most common React interview trap lives here: why setN(n+1) twice still only adds one.
Core idea. State updates are batched and deferred — not instant. Within a render your state is a frozen snapshot; to update based on the previous value use the functional updater setN(prev => prev + 1), and never mutate state.
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
this render
n =
0
frozen snapshot
update queue
empty — press a button below
Two ways to add 1 twice. Try each and watch the queue.
↑ play a little first, then dig in