Created
March 22, 2017 12:41
-
-
Save bora89/3abe614a2debf04ecbe80d00faa792d3 to your computer and use it in GitHub Desktop.
react pass props to this.props.children
This file contains hidden or 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
/** | |
* 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