Note on React Hooks / React Hooks 笔记

Posted by Pengyu on March 10, 2024

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() }


Creative Commons License
This work is licensed under a CC A-S 4.0 International License.