Redex-Hooks
閱讀時間:全文 139 字,預估用時 1 分鐘
創作日期:2019-10-24
上篇文章:Redex-Hooks
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
上篇文章:Redex-Hooks