Last active
March 21, 2017 12:52
-
-
Save john1jan/4f88598ff0e7b78504a689320d4c6c09 to your computer and use it in GitHub Desktop.
Passing Params Child Component
This file contains hidden or 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(valueFromChild) { | |
console.log("printParent", this); | |
console.log(this.state.message); | |
console.log("Value from child:", valueFromChild); | |
} | |
} | |
This file contains hidden or 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 { | |
constructor(props) { | |
super(props); | |
this.state = { message: 'I am Child ' }; | |
} | |
render() { | |
return <div> | |
<p> Child Component</p> | |
<input type="button" value="Print From Child" onClick={this.props.printParent("Mars")} /> | |
</div> | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment