user7366497
user7366497

Reputation:

How to use multiple multiActions in react/redux?

I am importing multiple multiactions into my component and using connect. I have import one multaction and it works just fine, but I can't figure out how to do multiple. Here is my code.

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

Upvotes: 2

Views: 402

Answers (1)

Mμ.
Mμ.

Reputation: 8542

You can pass create a mapDispatchToProps that uses bindActionCreators and pass that as a second argument to connect instead of actions.

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

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

Upvotes: 2

Related Questions