Bonus points if you also add a cleanup to your useEffect, to cancel the request when the component gets unmounted during fetching. In your current code the state update will produce an error if the component gets unmounted during fetching (cant update state of unmounted component).
I mostly agree with that, except that you should also cleanup if you do delayed state updates in your useEffect, to avoid updating state on unmounted components (which will result in an error).
Bonus points if you also add a cleanup to your useEffect, to cancel the request when the component gets unmounted during fetching. In your current code the state update will produce an error if the component gets unmounted during fetching (cant update state of unmounted component).
what do you think about this dev.to/csituma/do-i-need-to-use-cl...
I mostly agree with that, except that you should also cleanup if you do delayed state updates in your useEffect, to avoid updating state on unmounted components (which will result in an error).
Thank you, that's a great addition