Skip to content

Instantly share code, notes, and snippets.

@dnasca
Last active November 15, 2016 10:19
Show Gist options
  • Save dnasca/4241f0b6085c1bea01099f820d20409e to your computer and use it in GitHub Desktop.
Save dnasca/4241f0b6085c1bea01099f820d20409e to your computer and use it in GitHub Desktop.
passing props from Child to Parent
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