1.useContext
声明createContext
使用useContext
2.renducer规范state创建流程
3.dispatch规setState流程
所有使用到userModefier的地方用外部组件Wrapper包裹,这样读写的数据直接到Wrapper中了,userModefier里操作数据
4.connect高阶组件
避免了用写死的外部组件Wrapper包裹userModifier,在用的时候使用connect函数即可实现数据和操作分离的效果
5.有效减少render
当我们操作数据时所有组件全都进行了render
方式一 使用useMemo或useCallback
方式二 修改setState
增加subscrib订阅函数
在connnct中setState会进行重新render
抽出我们封装的redux
5.selecctor
connect新增参数selector
传参时使用
不传参数
6.实现selecctor的精准渲染
声明grouo并在幺儿子中使用
这时当user变化时,幺儿子组件也重新render
重新封装connct,判断data和newData是否变化
7.connct的第二个参数-- MapDispatchertoProps
修改connct
使用
优化使用方式
8.CreateStore(reducer,initState)
将reducerhestate变成外部参数
导出读写接口
使用
9.封装provider
使用
10.让redux支持异步action(支持函数action)
普通函数
promise函数
使用