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.
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