Skip to content

Instantly share code, notes, and snippets.

@sabesansathananthan
Last active April 23, 2021 12:03
Show Gist options
  • Save sabesansathananthan/a68f98fe58813d42db98e377af91377d to your computer and use it in GitHub Desktop.
Save sabesansathananthan/a68f98fe58813d42db98e377af91377d to your computer and use it in GitHub Desktop.
How React Components Are Reused
// High-order component definition
const higherOrderComponent = (WrappedComponent) => {
return class EnhancedComponent extends React.Component {
// ...
render() {
return <WrappedComponent {...this.props} />;
}
};
}
// Common component definition
class WrappedComponent extends React.Component{
render(){
//....
}
}
// Returns the enhanced components packaged by higher-order components
const EnhancedComponent = higherOrderComponent(WrappedComponent);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment