const initialState = { count: 0 }; function reducer(state, action) { switch (action.type) { case 'increment': return { count: state.count + 1 }; case 'decrement': return { count: state.count - 1 }; } } function Counter() { const [ state, dispatch ] = useReducer(reducer, initialState); const increment = () => dispatch({ type: 'increment' }); const decrement = () => dispatch({ type: 'decrement' }); return ( <> Count: {state.count} ); }