Last active
April 23, 2021 12:03
-
-
Save sabesansathananthan/a68f98fe58813d42db98e377af91377d to your computer and use it in GitHub Desktop.
How React Components Are Reused
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
// 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