Skip to content
public-library›Rules›React›Use functional updates when new state depends on old state

Use functional updates when new state depends on old state

When the next state is computed from the current state, pass an updater function to the state setter, such as setItems((current) => [...current, item]).

In the full rule