Skip to content

Instantly share code, notes, and snippets.

@giancarlosisasi
Created May 4, 2017 03:57
Show Gist options
  • Select an option

  • Save giancarlosisasi/c417ab20d0fcb4f784b3a95f57d443ee to your computer and use it in GitHub Desktop.

Select an option

Save giancarlosisasi/c417ab20d0fcb4f784b3a95f57d443ee to your computer and use it in GitHub Desktop.
// children component
class Children extends Component {
state = {
text: "text children"
}
changeText = () => {
this.setState({ text: "text from parent" })
};
render() {
<div>{this.state.text}</div>
}
}
// parent component
class Parent extends Component {
changeText = () => {
// execute method of children component
this.childrenComponent.changeText();
}
render(){
<div>
<Children ref={ el => {this.childrenComponent = el;} } />
</div>
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment