DEV Community

Discussion on: React useEffect fetching API

Collapse
miketalbot profile image
Mike Talbot • Edited

That fetch is going to happen 2x at the start. The first time when todos is [] and then it will happen again when it's the result of the fetch as the useEffect deps will have changed. Then actually doesn't it just keep going because the object is different in todos?

Collapse
shubhamtiwari909 profile image
ShubhamTiwari909 Author

I am still learning so don't know much about in detail for now

Collapse
lukeshiru profile image
LUKESHIRU • Edited

You just have to remove the [todos] in useEffect (leaving only []) and then the fetch will only run in the first render of the component.

Collapse
rbluena profile image
Rabii Luena

I admire you on the fact that you are still learning but you still want to each others from what you have learned so far. That is a winning attitude right there. I wanted to help but LUKE already did.

Thanks for sharing.

Thread Thread
shubhamtiwari909 profile image
ShubhamTiwari909 Author

Thank you