Skip to content

Instantly share code, notes, and snippets.

@SBub
Forked from shotaK/HOC.js
Created March 29, 2018 10:02
Show Gist options
  • Select an option

  • Save SBub/d7133927417cdf5acfa923ab0c550c8b to your computer and use it in GitHub Desktop.

Select an option

Save SBub/d7133927417cdf5acfa923ab0c550c8b to your computer and use it in GitHub Desktop.
React Higher Order Component with props validation.
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;
@SBub
Copy link
Author

SBub commented Mar 29, 2018

Implementation using stateless component:

const Enhance = (args) => (WrappedComponent) => { const EnhancedComponent = props => ( <WrappedIconComponent {...props} withTypeCheck={true} /> ); EnhancedComponent.defaultProps = { }; EnhancedComponent.propTypes = { }; return EnhancedComponent; };

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment