React · Frontend system thinking
When do you need a functional state update?
Short answer
Use a functional update when the next state depends on the previous state. React passes the latest queued value, which avoids stale reads and makes multiple updates in one event compose correctly.
A direct update captures the state value from the current render. If several updates are queued, they can overwrite each other. A functional updater receives the latest state from React's queue.
// Can lose updates when called multiple times in one event
setCount(count + 1);
setCount(count + 1);
// Both increments apply
setCount((current) => current + 1);
setCount((current) => current + 1);Where it matters
- Multiple updates in the same event or batch
- Updates inside timers, intervals or async callbacks
- Updates derived from the previous state, such as toggles, counters and queues
- Reducers and complex object updates where the previous state is an input
The updater must be pure. Do not mutate the previous state inside it, and do not perform side effects such as network requests. Return the next state.
Follow-ups you should expect
Interviewers use these to check whether the first answer was understanding or memorisation.
- 1Why can two direct increments produce only one increment?
- 2Do functional updates work with objects and arrays?
- 3Why must the updater be pure?
- 4When is a direct update safe?
Say it in the interview
I use a functional update when the next state depends on the previous state, especially if several updates may be queued in the same event or if the update happens in a timer. React passes the latest state, so the updates compose instead of overwriting each other. The updater must be pure and return a new state without mutating the old one.
Use this as a model, not a script. Saying it in your own words is what makes it survive follow-up pressure.
Related questions
Reading is step one
Now say it out loud.
Understanding an answer and delivering it under pressure are different skills. Rehearse this topic in a live React mock interview and get scored feedback on depth, clarity and confidence.