Skip to content

Instantly share code, notes, and snippets.

@kylpo

kylpo/block2.jsx Secret

Created June 21, 2017 23:23
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/c596a4f713cd0171bc3d19f42e4f1ce2 to your computer and use it in GitHub Desktop.
Save kylpo/c596a4f713cd0171bc3d19f42e4f1ce2 to your computer and use it in GitHub Desktop.
class Cloning_ extends React.Component {
componentDidMount() {
console.log('Cloning Mount')
}
render() {
console.log('Cloning Render')
const { children, ...propsToPass } = this.props
const child = React.Children.only(children)
console.log('ChildProps: ', child.props)
return React.cloneElement(child, propsToPass)
}
}
class Div extends React.Component {
static defaultProps = {
bye: 'bye'
}
componentDidMount() {
console.log('Div Mount')
}
render() {
console.log('Div Render')
return (
<div>{this.props.children}</div>
)
}
}
export default class App extends React.Component {
render() {
return (
<Cloning_>
<Div hi="hi" />
</Cloning_>
)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment