Created
April 27, 2021 09:01
-
-
Save sabesansathananthan/7a22b6d4619fddaf9b71b6870ac1beff 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
render() { | |
// Filter out extra props and don’t pass through | |
const { extraProp, ...passThroughProps } = this.props; | |
// Inject props into the wrapped component. | |
// Usually the value of state or an instance method. | |
const injectedProp = someStateOrInstanceMethod; | |
// Pass props to the Wrapped component | |
return ( | |
<WrappedComponent | |
injectedProp={injectedProp} | |
{...passThroughProps} | |
/> | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment