Skip to content

Instantly share code, notes, and snippets.

@kylpo

kylpo/block1.jsx Secret

Created May 22, 2017 18:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kylpo/74fe30085e5a9e8927a85d182a09265e to your computer and use it in GitHub Desktop.
Save kylpo/74fe30085e5a9e8927a85d182a09265e to your computer and use it in GitHub Desktop.
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