I have requirement to call child component method from parent component in reactjs. I have tried using refs but not able to do it. Can anyone please suggest any solution. Than
in your parent you can create a reference
in the constructor:
this.child = React.createRef();
in any function:
execute=(comment)=>{ this.child.current.addComment(); } render(){ return ( ) }
and in the Message(child) component
addComment=()=>{ console.log("Pi ", this.props); };