Last active
November 15, 2016 10:19
-
-
Save dnasca/4241f0b6085c1bea01099f820d20409e to your computer and use it in GitHub Desktop.
passing props from Child to Parent
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
class Parent extends React.Component { | |
constructor(props) { | |
super(props); | |
this.doSomething = this.doSomething.bind(this); | |
} | |
doSomething(value) { | |
// expecting value to be 'hello' | |
// ... | |
} | |
render() { | |
return <Child valueHandler={this.doSomething} />; | |
} | |
} | |
class Child extends React.Component { | |
constructor(props) { | |
super(props); | |
} | |
sendToParent(value) { | |
// send value back up to parent | |
this.props.valueHandler(value); | |
} | |
// ...whatever else | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment