Skip to content

Instantly share code, notes, and snippets.

@reharik
Created May 17, 2016 19:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save reharik/4abb0133dc50e76964d3f13031cf2a21 to your computer and use it in GitHub Desktop.
Save reharik/4abb0133dc50e76964d3f13031cf2a21 to your computer and use it in GitHub Desktop.
great containerFactory
const { connect } = require('react-redux');
module.exports = (storeKeys = [], transform, actions) => (component) => {
transform = transform || ((dataFromStore) => { return dataFromStore});
const mapStateToProps = (state, ownProps) => {
const storeDataObjs = storeKeys.map(key => ({ [key]: state[key] }));
const storeObj = Object.assign({}, ...storeDataObjs);
return transform(storeObj, ownProps);
};
return connect( mapStateToProps, actions )(component);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment