Open utterances-bot opened 2 years ago
Thanks, nice example
Thank you Dilshan, this worked for me.
Works great, thank you!
so it pass the alertUser function to parent using useEffect right? but what if alertUser try to access some variable from the child component? will it work and why?
Does this work with React 18 best practices https://beta.reactjs.org/learn/synchronizing-with-effects#
?
@muammarFaiz In that case, you would need add alertuser
to the dependency array of useEffect
, otherwise the function instance assigned to childFunc.current
will reference stale variables.
How To Call Child Function From Parent Component In React | Dilshan Kelsen
One way to call a child component's function from its parent is with the help of the useRef hook . Here's the gist of it: We pass a…
https://dilshankelsen.com/call-child-function-from-parent-component-in-react/