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