-
-
Save SBub/d7133927417cdf5acfa923ab0c550c8b to your computer and use it in GitHub Desktop.
React Higher Order Component with props validation.
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 React, { Component, PropTypes } from 'React'; | |
| export const Enhance = ComposedComponent => { | |
| class WrappedComponent extends Component { | |
| attachFunction() { | |
| ComposedComponent.attachFunction(); | |
| } | |
| render() { | |
| return <ComposedComponent {...this.props} additionalProps={this.state.additionalData} />; | |
| } | |
| } | |
| WrappedComponent.propTypes = { | |
| }; | |
| return WrappedComponent; | |
| }; | |
| export default Enhance; |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Implementation using stateless component:
const Enhance = (args) => (WrappedComponent) => { const EnhancedComponent = props => ( <WrappedIconComponent {...props} withTypeCheck={true} /> ); EnhancedComponent.defaultProps = { }; EnhancedComponent.propTypes = { }; return EnhancedComponent; };