-
-
Save kylpo/74fe30085e5a9e8927a85d182a09265e to your computer and use it in GitHub Desktop.
This file contains 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
export class InjectorComponent extends React.Component { | |
render() { | |
const propsToPass = computePropsToPass(this.props) | |
// cloneElement requires a single child, no arrays | |
const Child = React.Children.only(this.props.children) | |
// does not render anything additional to Child | |
return React.cloneElement(Child, propsToPass) | |
} | |
} | |
// Used later like... | |
<InjectorComponent | |
something={something} | |
another='another' | |
> | |
<ChildToInjectTo /> | |
</InjectorComponent> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment