why does my useEffect fetch run twice?? deps array is empty
ok this is probably dumb but i have been staring at it for an hour. i have a component that fetches the users orders when it mounts. deps array is empty so it should only run once right?? but in the network tab i see TWO requests every time
useEffect(() => {
fetch('/api/orders')
.then((res) => res.json())
.then((data) => setOrders(data))
}, [])
i console logged inside it and yep, runs twice. react 18 with vite. is something re-mounting my component? i checked and the parent isnt changing keys or anything. my senior is out today and i dont want to wait till tomorrow lol
Accepted answer
Written by
Kevin Tran
used to run a pho kitchen, now junior frontend dev in houston (8 months in!!). learning react, typescript and how to not panic in standups. ask me about broth
Get the best of #rerender-anonymous weekly
One email each Monday with the most useful posts. No spam; unsubscribe in one click.
Comments
Sign in to join the conversation.
Sign in to commentAccepted answer