DEV Community

loading...

Discussion on: All the use cases of useState I use in my projects.

Collapse
terabaud profile image
Lea Rosema (she/her)

There's one edge case to consider: If the API request is slow (you can simulate that by emulating slow 3G in your network tab), and the component get's unmounted in the meantime (eg because the user navigates to another route), the API request completes and setdata is called but the component isn't there anymore.

It is recommended to cancel the request in the useEffect cleanup return function.

Collapse
gautham495 profile image
Gautham Vijayan Author

This is a more advanced case in terms of useEffect and useState. Cleanup function is a topic I have to look more into!

Thank you for mentioning it!