useReducer

const ACTIONS = { INCREMENT:'inc', DECREMENT:'dec' } const reducer = (state, action) => { if(action.type === ACTIONS.INCREMENT){ return state + 1 }else if(action.type === ACTIONS.DECREMENT){ return state - 1 } return state; }; const [state , dispatch] = useReducer(reducer , inatialState = 0)