UseReducer
function reducer(state, action) { switch(action.type) { case ‘increment’: return { count: state.count + 1 } case ‘decrement’: return { count: state.count - 1 } default: return state; } }
const [state, dispatch] = useReducer(reducer, {count:0})
function increment() { dispatch() }
This work is licensed under a CC A-S 4.0 International License.