DEV Community

Discussion on: Cleaning up Async Functions in React's useEffect Hook (Unsubscribing)

Collapse
joeattardi profile image
Joe Attardi

Using an isMounted approach is somewhat of an antipattern, whenever possible it's better to cancel the request (in the fetch example, you can use AbortController to cancel the request).

Collapse
elijahtrillionz profile image
Elijah Trillionz Author

Thanks for this. I do know using the mounted approach is probably not the best way, but it's a way around it.
I will try using the AbortController as suggested.
Thanks.

Collapse
tanth1993 profile image
tanth1993

yeah. I don't like using isMounted, but in React component this is maybe the common way to handle the unmount component

Collapse
gnt profile image
gntsketches • Edited on

Can you say more about why using the mounted variable is an antipattern? Thanks!

Some comments have been hidden by the post's author - find out more