Why is hello from provider printed last?
Order of Hook Execution:
When the Game
component is rendered, it first executes the custom hook useHoo
, which runs any useEffect
inside it.
Provider's useEffect: The useEffect in GameProvider
will fire after the component has rendered and React has finished processing all the hooks in game.jsx
.
Effect Execution Order: React schedules effects
to run after the render phase, so the order of execution you’re observing is because React first runs
the useEffect
in useHoo
, then runs the one in Game
, and finally the one in GameProvider
.