Created
May 17, 2016 19:06
-
-
Save reharik/4abb0133dc50e76964d3f13031cf2a21 to your computer and use it in GitHub Desktop.
great containerFactory
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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