How it works
React 19.3.1 keeps each useState call's state in a hook object on the component's fiber, matched to the call by its position (implementation details from ReactFiberHooks.js; see the Rules of Hooks question for the ordering). The hook holds the committed value (memoizedState) and a queue of pending updates. useState returns [hook.memoizedState, setter], and your destructuring copies the value into a local constant.
The setter is dispatchSetState, bound to that fiber and queue when the component mounted, which is why its identity never changes. It appends an update object to the queue and schedules a render. It never touches your variable. On the next render, useState walks the queue, applies the updates to the base state and returns the result. That is the only place a new value appears.
The rest is ordinary JavaScript. Each call of your component creates a new environment with its own count; functions created during that call close over that environment, exactly like callbacks created in separate calls of any function. After the commit, the new render's handlers are the ones React calls, so the next click runs code that closes over the new value.
Edge cases
An await doesn't change anything, because the variable belongs to the call, not to the moment:
function SendButton() {
const [status, setStatus] = useState('idle');
console.log('render', status);
async function handleClick() {
setStatus('sending');
await new Promise((resolve) => setTimeout(resolve, 200));
console.log('after await', status);
}
return <button onClick={handleClick}>Send</button>;
}
// After a click:
// → render sending
// → after await idle
Chrome 156 and Firefox 159, development and production builds. The component had rendered with 'sending' before the await finished; the handler still read 'idle'.
- Updater functions are the exception to the snapshot: React passes them the pending state from the queue, so they compose. That's the subject of the batching question.
- Objects are captured by reference. The snapshot is the reference, not a deep copy. If someone mutates the object, an old closure sees the mutation, which is one more reason state must be updated immutably.
- Refs aren't snapshotted.
ref.current read in a timeout returns whatever it holds at that moment. That's why refs are the escape hatch for "latest value" reads, and why reading them during render is discouraged.
Real-world scenario
A draft editor autosaves with useEffect(() => { const id = setInterval(() => save(draft), 5000); … }, []). Every save sends the empty initial draft, because the interval closed over the first render. Listing draft as a dependency fixes the value but restarts the timer on every keystroke, so a fast typist never triggers a save. The usual fix keeps the interval stable and reads the current draft from a ref the component keeps updated, or from an Effect Event.
The snapshot is what you want in the opposite case. react.dev's example sends a message after a five-second delay: if the user switches the recipient during the delay, the message still goes to the person who was selected when they pressed Send.
Trade-offs
Snapshots make each render internally consistent: its output, its handlers and its effects all agree on one set of values, and React can prepare a render with newer state, as concurrent rendering does, without changing the handlers already on screen. The cost lands on long-lived callbacks, which have to opt into fresh values explicitly through updaters, dependencies or refs. Class components chose the other side: this.state is always current, and so a timeout can read state that no longer matches what it was scheduled for.