Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Undistraction/c421369031fc3db1d0838d2c97069717 to your computer and use it in GitHub Desktop.
Save Undistraction/c421369031fc3db1d0838d2c97069717 to your computer and use it in GitHub Desktop.
Redux Container With Dynamic Component
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