DEV Community

Discussion on: React useEffect fetching API

tmartinri profile image

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

shubhamtiwari909 profile image
ShubhamTiwari909 Author

Yes it will also work good