摘要: 引入 对于函数组件 const App = props => { const [n, setN] = useState(0) //... } 在setN执行后: n不会被setN改变(重要!) 会触发UI更新,App()再次执行,再次useState(0)时,得到n的值不同 分析: setN将n的新 阅读全文
posted @ 2021-11-24 11:50 brave-sailor 阅读(576) 评论(0) 推荐(0) 编辑
摘要: 在 hooks 中提供了的 useReducer 功能,可以增强 ReducerDemo 函数提供类似 Redux 的功能,引入 useReducer 后,useReducer 接受一个 reducer 函数作为参数,reducer 接受两个参数一个是 state 另一个是 action 。然后返回 阅读全文
posted @ 2021-11-24 11:40 brave-sailor 阅读(162) 评论(0) 推荐(0) 编辑
摘要: 用来践行Flux/Redux的思想 一共分为四步: 创建初始值initialState const initial = { n:0 } 创建所有操作reducer(state,action) const reducer = (state ,action)=>{ if(action.type 'add 阅读全文
posted @ 2021-11-24 11:25 brave-sailor 阅读(42) 评论(0) 推荐(0) 编辑