Last active
June 21, 2019 00:18
-
-
Save ricexen/283ce1f575075716d8b208ef3c1f4251 to your computer and use it in GitHub Desktop.
This file contains 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
import { connect } from 'react-redux'; | |
import { bindActionCreators } from 'redux'; | |
export const createContainer = (props, actions, component) => { | |
props = !Array.isArray(props) ? [props] : props; | |
const mapStateToProps = state => { | |
let states = {}; | |
for (let i = 0; i < props.length; i++) { | |
const prop = props[i]; | |
if (state[prop]) { | |
states[prop] = state[prop].toJS(); | |
} | |
} | |
return states; | |
}; | |
function mapDispatchToProps(dispatch) { | |
return bindActionCreators(actions, dispatch); | |
} | |
return connect(mapStateToProps, mapDispatchToProps)(component); | |
} | |
export default createContainer; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment