I'm using a useEffect
as a componentWillMount
, but it is behaving unexpectedly.
In Component
, (as you can see in the Codesandbox below), the code in useEffect
should fire before the return
content is hit, but for some reason, the useEffect
is entered after the DOM has loaded.
In the below sandbox, I'm loading two images, imgsSrc1
and imgsSrc2
. In my useEffect
, I'm creating an image DOM element, and setting its src
prop to imgsSrc1
. In my return
, I have an img
element that has its src
prop set to imgsSrc2
.
I would expect imgsSrc1
to start downloading first, but when I look into the network tab of the dev console, I see that imgsSrc2
starts downloading first:
Why is this happening? Is this NextJS behavior?