Skip to content

Instantly share code, notes, and snippets.

@kylpo

kylpo/block1.jsx Secret

Created Jun 21, 2017
Embed
What would you like to do?
class Press_ extends React.Component {
render() {
// React.cloneElement() requires a single child
const Child = React.Children.only(this.props.children)
// compute props to pass
const propsToPass = {onPress: this.props.onPress}
// return new element with props to pass
// note: this could also be wrapped in other components, if we wanted
return React.cloneElement(Child, propsToPass)
}
}
class MyComponent extends React.Component {
handlePress = () => {
// ...
}
render() {
return (
<Press_ onPress={this.handlePress}>
<div />
</Press_>
)
}
}
ReactDom.Render(<MyComponent />, /* ... */)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.