DEV Community

Discussion on: The Definitive React Hooks Cheatsheet

Collapse
 
juliang profile image
Julian Garamendy

Hi Antonin, Thanks for writing this. I think it's very useful.

I have one comment regarding your useUser hook. I think it's important to "cancel" the request before the component unmounts to avoid memory leaks.
I wrote about it a few days ago. You might want to have a look:
dev.to/juliang/cancelling-a-promis...

Cheers!

Collapse
 
guico33 profile image
guico33

In this case there's no memory leak though.
It's simply a warning as updating the state will effectively do nothing after the component has been unmounted.

Collapse
 
juliang profile image
Julian Garamendy

Ah. I see your point. I suppose the dangling reference to the component gets garbage-collected after the promise resolves and state is updated?