Skip to content

Instantly share code, notes, and snippets.

@bora89
Created March 22, 2017 12:41
Show Gist options
  • Save bora89/3abe614a2debf04ecbe80d00faa792d3 to your computer and use it in GitHub Desktop.
Save bora89/3abe614a2debf04ecbe80d00faa792d3 to your computer and use it in GitHub Desktop.
react pass props to this.props.children
/**
* pass props to this.props.children
* see http://stackoverflow.com/questions/32370994/how-to-pass-props-to-this-props-children
*/
const childrenWithProps = React.Children.map(this.props.children,
(child) => React.cloneElement(child, {
onGo: (value) => {
// invoke child onGo event (if any)
if (child.props.onGo) {
child.props.onGo(value);
}
// do our own logic
this.enterResultMode();
}
})
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment