Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Could bindActionCreators optionally take a list of action objects? #363

Closed
muffinresearch opened this issue Jul 30, 2015 · 9 comments
Closed

Comments

@muffinresearch
Copy link

We've got a few places in our code where we're passing multiple objects of bound actions into components. It would great to have the optionally pass a list of action objects into bindActionCreators.

bindActionCreators([SomeActions, OtherActions], dispatch)

The caveat of course would be duplicate actions would get overwritten by the last one processed.

@muffinresearch muffinresearch changed the title Could bindActionCreators optionally take a list of actions? Could bindActionCreators optionally take a list of action objects? Jul 30, 2015
@gaearon
Copy link
Contributor

gaearon commented Jul 30, 2015

You can do this with ES7 object spread proposal:

bindActionCreators({ ...SomeActions, ...OtherActions }, dispatch)

or (vanilla ES6, needs Object.assign polyfill or Babel plugin)

bindActionCreators(Object.assign({}, SomeActions, OtherActions), dispatch)

or (ES5, assumes lodash)

var assign = require('lodash/object/assign');

bindActionCreators(assign({}, SomeActions, OtherActions), dispatch)

@muffinresearch
Copy link
Author

Ah excellent, that's even easier. Thanks!

@backnotprop
Copy link

🙌

@rjmacarthy
Copy link

This is helpful! Thanks!

@phoenixbox
Copy link

Super helpful! 🌟

@aweary
Copy link
Contributor

aweary commented Mar 11, 2016

@gaearon should this possibly be added to the tips section in the bindActionCreators API doc?

@gaearon
Copy link
Contributor

gaearon commented Mar 11, 2016

A pull request is welcome 😉
I’m not actively working on the docs right now so my answer is the same: “if you’d like something to be in the docs, please send a PR”.

@WonSong
Copy link

WonSong commented May 9, 2016

Not sure if this will help anyone, but I was trying to combine my app actions and Actions from react-native-router-flux, and below worked for me.

import * as AppActions from './actions';
import { Actions } from 'react-native-router-flux';

function mapDispatchToProps(dispatch) {
  return { actions: {...bindActionCreators(AppActions , dispatch), ...Actions } };
}

@gaearon
Copy link
Contributor

gaearon commented May 9, 2016

Not sure if this will help anyone, but I was trying to combine my app actions and Actions from react-native-router-flux, and below worked for me.

This is a little confusing because Actions from react-native-router-flux seem to have nothing in common with Redux, and probably shouldn’t be in mapDispatchToProps at all. Just use them directly in your components.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants