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

Taught in

References