Skip to content

Instantly share code, notes, and snippets.

@john1jan
Last active March 20, 2017 15:57
Show Gist options
  • Save john1jan/6a3b9ebb8c26e65477e4c118d14327ef to your computer and use it in GitHub Desktop.
Save john1jan/6a3b9ebb8c26e65477e4c118d14327ef to your computer and use it in GitHub Desktop.
Parent Child
class Parent extends React.Component {
constructor(props) {
super(props);
this.state = { message: 'I am parent ' };
this.printParent = this.printParent.bind(this);
}
render() {
return <div>
<p>Parent Component</p>
<ChildComponent printParent={this.printParent} />
</div>
}
printParent() {
console.log(this.state.message);
}
}
class ChildComponent extends React.Component {
render() {
return <div>
<p> Child Component</p>
<input type="button" value="Print From Child" onClick={this.props.printParent} />
</div>
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment