Created
March 1, 2017 10:59
-
-
Save Undistraction/c421369031fc3db1d0838d2c97069717 to your computer and use it in GitHub Desktop.
Redux Container With Dynamic Component
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
import { connect } from 'react-redux'; | |
import React from 'react'; | |
import { loadStepDataRequest } from '../../redux/actions'; | |
import getStepByUid from '../../redux/selectors/getStepByUid'; | |
import * as PropTypes from '../proptypes'; | |
// Take state and feed in to component props | |
const mapStateToProps = (state, ownProps) => ({ | |
step: ownProps.step, | |
isManaged: state.config.runIsAuto, | |
}); | |
const mapDispatchToProps = (dispatch, ownProps) => ({ | |
onLoadClick: () => { | |
dispatch(loadStepDataRequest(ownProps.step.uid)); | |
}, | |
}); | |
const connection = connect(mapStateToProps, mapDispatchToProps); | |
const RendererContainer = ({ component, step }) => | |
React.createElement(connection(component), { step }); | |
RendererContainer.propTypes = { | |
component: React.PropTypes.element.isRequired, | |
step: PropTypes.step.isRequired, | |
}; | |
export default RendererContainer; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment