Posted In: Java Script, React

React JS – How to call parent method

To call ‘parent method’ from Child ‘parent method’ should be passed as props to Child. Then Child can use it by accessing this.props.
For example you want to refresh Parent after some change in Child

------------------------------------------------------
var Parent = React.createClass({
handleGridRefresh() {
}
......
<Child employee={this.state.employee} handleGridRefresh={this.handleGridRefresh} />
 
------------------------------------------------------
var Child = React.createClass({
....
//access props 
this.props.employee
//this will call handleGridRefresh() from Parent
this.props.handleGridRefresh();
------------------------------------------------------

Tags: ,

by , on February 7th, 2017

  • Categories