diff --git a/随时随地/简单的 React 思考 - useReducer.md b/随时随地/简单的 React 思考 - useReducer.md index 5a2a2e3..0bc023e 100644 --- a/随时随地/简单的 React 思考 - useReducer.md +++ b/随时随地/简单的 React 思考 - useReducer.md @@ -5,7 +5,8 @@ const [state, dispatch] = useReducer(reducer, initialArg, init); ``` -React 官网的 useReducer 实现计数器案例 +React 官网的 useReducer + ```javascript const initialState = {count: 0}; @@ -30,4 +31,15 @@ function Counter() { ); } -``` \ No newline at end of file +``` + +最简的 useReducer 实践 + +```javascript +const [state, dispatch] = useReducer((state, action) => ( + { ...state, action }), + initState +) +``` + +在这个最简单的事件中,useReducer 就充当了 useState 的替代,dispatch 修改状态,返回最新的 state \ No newline at end of file