美文网首页
对于redux中bindActionCreators的理解

对于redux中bindActionCreators的理解

作者: AUL | 来源:发表于2018-05-16 12:18 被阅读65次
const mapDispatchToProps = dispatch => {
  return {
    ...bindActionCreators(appActions, dispatch)
  };
};

export default connect(mapStateToProps, mapDispatchToProps)(App);

调用了bindActionCreators方法把action绑定到了connect方法中,其中connect方法的作用是连接react组件和redux store,也就是说通过connect方法子组件可以获取store中的state和dispatch。

bindActionCreators的作用是将一个或多个action和dispatch组合起来生成mapDispatchToProps需要生成的内容。

按我理解 就是通过connect() 高阶函数获取 state 以及store的 dispatch,再通过bindActionCreators() 与action creators绑定

相关文章

网友评论

      本文标题:对于redux中bindActionCreators的理解

      本文链接:https://www.haomeiwen.com/subject/dnfpdftx.html