Introduction
const reducer = (state, action) => {
switch (action.type) {
case "SOME_ACTION":
// update state
return {
age: state.age + 1
}
break;
default:
return state
}
}
const [state, dispatch] = useReducer(reducer, {age: 32})
function handleClick() {
dispatch({type: "SOME_ACTION"})
}