useReducer

The React hook that manages state through a reducer function, returning the current state and a dispatch function.

In more detail

Instead of calling setters directly, components dispatch actions describing what happened, and the reducer decides how the state changes. It suits state where several values change together, such as a request that moves between idle, loading, success and error.

Example

const [state, dispatch] = useReducer(requestReducer, { status: "idle" });

Related terms

Taught in

References