I want to call a method exposed by a React component from the instance of a React Element.
For example, in this jsfiddle. I want to call the alertMessage
method 1 using ChildRef:
public childRef: any = React.createRef();
public onButtonClick= () => {
console.log(this.childRef.current); // this will have your child reference
}
Method 2: using window register
public onButtonClick= () => {
console.log(window.yourRef); // this will have your child reference
}
{window.yourRef = ref} }/>`