React state does not update immediately after setState because a state setter does not change the variable you already hold. It schedules a re-render, and the new value is only available in the next render. Inside the current event handler, the variable still holds the value from the render that created it.
This is the behaviour you see when you log a state variable right after calling its setter and get the old value. It is by design, and once you understand snapshots you can write code that works with it. Examples use React 19 and function components.
Each render of a component gets its own constants: its props, its handlers and its state values. When you call setCount(count + 1), React queues the update and re-renders later. The count in your running handler is a const from the earlier render and cannot change.
The screen shows 1 after the first click, but the log printed 0, because it ran before the next render.
Because the handler sees a fixed snapshot, repeating the same update does not stack.
All three calls queue "set the count to 1", so the result is 1, not 3. React did what you asked: each call replaced state with a value computed from the same stale count.
Pass a function to the setter and React calls it with the latest queued state, not with your snapshot.
The queue now runs c => c + 1 three times in order, so the count ends at 3. Use the updater form whenever the new value depends on the previous value, and always inside async callbacks, timers and effects where your closure may be old.
Sometimes you need the value you just set. There are three clean options.
For side effects that must follow a committed state, use useEffect with the state in the dependency array.
Do not store the "latest" value in a second state variable just to read it sooner. Derive it or compute it locally.
A setTimeout or fetch callback closes over the state from the render in which it was created. If state changes while it waits, the callback still sees the old value.
React renders the screen for the new state, but this alert reports the snapshot of the click. If the timer needs the latest value, read it through a ref or use the updater form.
Then read latest.current inside the callback.
If you mutate an object held in state and call the setter with the same reference, React sees no change and may skip rendering. Always pass a new object or array.
A mutation such as user.name = 'Asha' also makes the problem confusing, because the object seems to change right away while the screen does not.
flushSync from react-dom forces React to apply the update to the DOM synchronously, for example before measuring or scrolling to a new element.
Even then, the state variable in your closure is still the old snapshot. flushSync only guarantees the DOM is updated. It disables batching and costs performance, so use it rarely.
It is better described as deferred. The call returns immediately, and React applies the update during the next render. The variable you hold never changes within that render.
The log runs before React re-renders, so it prints the snapshot from the current render. Log inside the component body or in an effect to see the new value.
Class this.setState is also batched, but this.state is read from the instance, so the symptom looks slightly different. Pass a callback or an updater function to setState in classes for the same fix.
React passes the most recent pending state to the updater, so each call builds on the last one instead of on the stale snapshot.
State is a snapshot, and setters schedule the next render instead of changing the current one. Use updater functions for updates that depend on previous state, compute derived values locally, react to committed state with effects, and avoid flushSync unless you must touch the DOM immediately.