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.
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.
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!