I am trying to access a child method from the parent component. This is how the child code looks like
class child extends Component {
someMethod(v) {
// do something
}
render(){
return(
...
)
}
}
And this is the parent code
class Parent extends Component {
hoverOn(){
this._Child.someMethod(10); // _Child is undefined here
}
render(){
return(
<div onMouseOver={this.hoverOn.bind(this)}>
<OtherChild ....>
<Child ref={(Child) => { this._Child = Child; }} />
</div>
)
}
}
On hoverOn() I get an error telling me that _Child is undefined. How can I call someMethod() from the Parent Class?