I am new to react and I have been checking ways of triggering a child function from my parent. So far I found two ways in the following threads.
useImperativeHandle Post by rossipedia
UseEffect - Post by bennygenel
Additionally, most examples i seen aside from the post by bennygenel are using reference to handle this issue. Which comes in the form of referencing the child object
and calling it's function
or through the usage of useImperativeHandle
to directly reference the function
itself. Hence, I am curious if ref
is indeed a good way of approaching this, as there might be mutations in between causing ref to be somewhat dangerous to use. On the other hand, triggering through a props sent from the parent to the child to trigger a function useEffect
seems safer as there is not a need to worry for mutations inbetween.
Please do correct me if I have misunderstood anything thanks.