Skip to content

Instantly share code, notes, and snippets.

@sabesansathananthan
Created April 27, 2021 09:01
Show Gist options
  • Save sabesansathananthan/7a22b6d4619fddaf9b71b6870ac1beff to your computer and use it in GitHub Desktop.
Save sabesansathananthan/7a22b6d4619fddaf9b71b6870ac1beff to your computer and use it in GitHub Desktop.
How React Components Are Reused
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