Redex-Hooks
Reading Time:The full text has 139 words, estimated reading time: 1 minutes
Creation Date:2019-10-24
Previous Article:Redex-Hooks
Next Article:TypeScript学习笔记-tsconfig配置
BEGIN
应React16.8+
增加的Hooks API
, React Redux
增加API用于同步connect()
的功能
需要用到的引用:
import {
shallowEqual,
useSelector,
useDispatch,
useStore,
} from 'react-redux';
useSelector()
使用如下: const result : any = useSelector(selector : Function, equalityFn? : Function)
其中第一个参数用于获取store中的数据, 相当于connect函数的第一个参数.
第二个参数为可选参数, 如果不传则数据做浅层对比, 可以传react-redux
的shallowEqual
方法, 或者lodash
的isEqual
方法
useDispatch()
返回操作redux的触发器const dispatch = useDispatch();
useStore()
返回store实例: const store = useStore();
FINISH
Previous Article:Redex-Hooks
Next Article:TypeScript学习笔记-tsconfig配置