Last active
March 20, 2017 15:57
-
-
Save john1jan/6a3b9ebb8c26e65477e4c118d14327ef to your computer and use it in GitHub Desktop.
Parent Child
This file contains 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.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); | |
} | |
} | |
This file contains 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 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