Skip to content

Instantly share code, notes, and snippets.

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