1
ReactIntermediate#hooks
Use useReducer when several values change together, the next state depends on the previous one through many actions, or you want the update logic testable outside the component.
function reducer(s, a) {
switch (a.type) {
case 'inc': return { ...s, n: s.n + 1 };
default: return s;
}
}
const [state, dispatch] = useReducer(reducer, { n: 0 });
dispatch({ type: 'inc' });