Created
March 26, 2017 12:57
-
-
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
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
/* 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