如何在react / redux中使用多个multiAction?

时间:2017-06-30 14:30:47

标签: reactjs redux react-redux

我正在将多个多重参与导入到我的组件中并使用connect。我已经导入了一个多线程,它工作正常,但我无法弄清楚如何做多个。这是我的代码。

import React, { Component } from 'react';
import { connect } from 'react-redux';
import { Link } from 'react-router-dom';
import * as actions from '../../actions/posts_actions';
import * as actionsIndex from '../../actions/index';
import * as actionsComments from '../../comments_actions';

function mapStateToProps({ posts }, ownProps) {
  return { post: posts[ownProps.match.params.id] };
}

export default connect(mapStateToProps, actions)(ShowPosts);

1 个答案:

答案 0 :(得分:2)

您可以传递创建使用bindActionCreators的mapDispatchToProps,并将其作为第二个参数传递给connect而不是操作。



const mapDispatchToProps = (dispatch) => ({
    actions: bindActionCreators(Object.assign({}, actions, actionsIndex, 
    actionsComments), dispatch)
});

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