Skip to content

Instantly share code, notes, and snippets.

@marlo22
Last active July 5, 2019 12:53
Show Gist options
  • Save marlo22/9359dd4f765a6b6aaf51d26a5c0a51f4 to your computer and use it in GitHub Desktop.
Save marlo22/9359dd4f765a6b6aaf51d26a5c0a51f4 to your computer and use it in GitHub Desktop.
reference
class Parent extends Component {
methodFromChild = () => null;
getMethodForMe = method => {
this.methodFromChild = method;
}
render() {
return <Child setFunctionReference={this.getMethodForMe} />
}
}
class Child extends Component {
componentDidMount() {
this.props.setFunctionReference(this.methodForParent);
}
methodForParent = () => {
// do something
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment