Table of Contents:
  1. useSelector()
    1. useDispatch()
      1. useStore()

        Redex-Hooks

        Reading Time:The full text has 139 words, estimated reading time: 1 minutes
        Creation Date:2019-10-24
        Article Tags:
        Previous Article: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
        Previous Article:Redex-Hooks

        Random Articles
        Life Countdown
        default