1

I have a react app with parent component app.js and a child component homepage.js.

So when I refresh the page useEffect hook from homepage.js runs first and then app.js useEffect runs but I have some functionality that is dependent on app.js useEffect I want that code run automatically after page refresh and after the useEffect in app.js.

  • take a look at this answer, you might get your answer https://stackoverflow.com/questions/58352375/what-is-the-correct-order-of-execution-of-useeffect-in-react-parent-and-child-co – Ganesh B. Kadam Nov 20 '21 at 05:56
  • Earlier I was looking at that document it was very helpful but I actually need a way to execute few lines of codes after execution of parent component useEffect. and because the child component useEffect runs before parent component useEffect on refresh so I can not put it there. Thanks for quick reply! – Susmit Deshpande Nov 20 '21 at 06:07
  • Take a look at this answer, you might get your answer: https://stackoverflow.com/questions/69340168/react-hooks-child-component-useeffect-executes-first-before-parent-component – Madeefar Abbas Nov 20 '21 at 06:08

1 Answers1

0

if you want to execute parent component code first then in parent instead of using useEffect() execute that code in useMemo()

  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Nov 20 '21 at 08:19