DEV Community

Discussion on: React useEffect fetching API

Collapse
 
tmartinri profile image
tmartin-ri

I would say that if you only want it to run the first time your component loads you should leave the useEffects dependency empty but at my work we use exhaustive deps on the linter and it would throw an error for emptying the dependency array. Instead I would recommend putting the fetch in an if statement that checks todos.length === 0

Collapse
 
shubhamtiwari909 profile image
Shubham Tiwari

Yes it will also work good