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));



    欢迎讨论,如果不正,劳请指出
  • 相关阅读:
    各种模板
    HNOI2019总结
    WC2019游记
    THUSC2017 Day1题解
    NOIP2018联赛总结
    LOJ2557. 「CTSC2018」组合数问题
    NOI2018游记
    bzoj4671: 异或图
    sg函数小结
    [NOI2011]Noi嘉年华
  • 原文地址:https://www.cnblogs.com/jiangbanji/p/7746429.html
Copyright © 2011-2022 走看看