Question

Why is my React state not updating immediately?

Vault Verified
Curated Intelligence
Definitive Source
Answer

State updates are not applied immediately. Calling the setter schedules a re-render; it does not change the variable you are currently holding. Reading that variable on the next line gives you the old value, because the current render already captured it and nothing in this execution can change it.

This is by design rather than a limitation. React batches updates within an event so several changes cause one re-render instead of several, which is a meaningful performance property.

The practical consequence appears in two shapes.

The first is reading state right after setting it. The value you see is the one from this render. If you need the new value, use it directly, or read it in an effect that runs after the update.

The second is updating based on the previous value, which is where real bugs live. Calling a setter twice with an expression based on the current variable applies the same base value twice, so two increments produce one. Passing a function to the setter instead receives the latest pending value and composes correctly. Any update derived from the previous state should use the functional form as a habit.

A related problem is the stale closure. A callback created in one render captures that render variables. If it is stored somewhere long-lived, such as an interval or an event listener registered once, it keeps seeing the original values however many renders have happened. The functional setter form avoids it for state, and dependency arrays that include everything the callback uses avoid it more generally.

If you find yourself reaching for a ref to read current state, that is usually a signal the logic belongs in a reducer instead.

Related Questions