updater function
A function passed to a state setter that receives the latest pending state and returns the next state.
In more detail
setCount((prev) => prev + 1) queues a calculation rather than a fixed value, so several updates in a row all apply. Use it whenever the next state depends on the previous one, and keep it pure.
Example
setItems((prev) => [...prev, newItem])Related terms
- useState — The React hook that adds a state variable to a component and returns the current value with a function to change it.
- state snapshot — The idea that during one render every state value is fixed, so code in that render always sees the same value even after calling a setter.
- pure function — A function whose result depends only on its arguments and which has no side effects, so the same inputs always give the same output.
Taught in
- State with useState: Immutability And Asynchronous Batching — React 19 & Modern Component Architecture