I have a navbar component which has few buttons, I want to run a function in another component (which uses state variables and some refs). I am using Redux as state manager. Currently the way I'm achieving the task is by having a runFunction = 1 in the Redux store and increment this by 1 on button click. In the main component (which has the function), I have wrapped the function with a useEffect with runFunction as dependency, so whenever runFunction changes, my function gets called. Something like this:
useEffect(()=>{ someFunction() }, [runFunction])
Is this the right way to do so ? Is there any better method to achieve this ?