Skip to content

Instantly share code, notes, and snippets.

@davidfurlong
Created March 26, 2017 12:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save davidfurlong/4f67c7807da747194a9d48eb9dc712ac to your computer and use it in GitHub Desktop.
Save davidfurlong/4f67c7807da747194a9d48eb9dc712ac to your computer and use it in GitHub Desktop.
React HOC which returns a Stateless Functional component which has contextTypes or defaultProps or propTypes
/* its not immediately obvious how to do this, which is why I've added it here */
const connectSubmitButton = (WrappedComponent) => {
const connectContext = (props, context) => (<WrappedComponent {...props} _reduxForm={context._reduxForm} />);
connectContext.contextTypes = {
_reduxForm: PropTypes.object.isRequired
};
return connectContext;
};
// example usage
export default connectSubmitButton(SubmitButton);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment