zoukankan      html  css  js  c++  java
  • redux中的bindActionCreators的作用简述

    Turns an object whose values are action creators, into an object with the
    * same keys, but with every function wrapped into a `dispatch` call so they
    * may be invoked directly. This is just a convenience method, as you can call
    * `store.dispatch(MyActionCreators.doSomething())` yourself just fine.

    以上是一段源码的注释,意思是我们不需要使用dispatch了,,调用bindActionCreators后返回的action就可以了,返回action集合对象中所有action方法都被包了一层dispatch

    function bindActionCreator(actionCreator, dispatch) {
      return (...args) => dispatch(actionCreator(...args))
    }
    

      这里是关键源码,就是帮你包了一层dispatch。一般配合

    mapDispatchToProps把action传到props里面,然后直接this.props.someAction(someArgs)就等同于,你dispatch(someAction(someArgs));



    欢迎讨论,如果不正,劳请指出
  • 相关阅读:
    作业07-Java GUI编程
    作业06-接口、内部类
    作业05-继承、多态、抽象类与接口
    作业14-数据库
    作业13-网络
    作业12-流与文件
    作业11-多线程
    作业10-异常
    作业09-集合与泛型
    作业08-集合
  • 原文地址:https://www.cnblogs.com/jiangbanji/p/7746429.html
Copyright © 2011-2022 走看看