目錄:
  1. useSelector()
    1. useDispatch()
      1. useStore()

        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-reduxshallowEqual方法, 或者lodashisEqual方法

        useDispatch()

        返回操作redux的触发器const dispatch = useDispatch();

        useStore()

        返回store实例: const store = useStore();

        FINISH
        上篇文章:Redex-Hooks

        隨機文章
        人生倒計時
        default