Skip to content

Instantly share code, notes, and snippets.

@ricexen
Last active June 21, 2019 00:18
Show Gist options
  • Save ricexen/283ce1f575075716d8b208ef3c1f4251 to your computer and use it in GitHub Desktop.
Save ricexen/283ce1f575075716d8b208ef3c1f4251 to your computer and use it in GitHub Desktop.
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