DEV Community

Discussion on: Clean Up Async Requests in `useEffect` Hooks

Collapse
 
trickydisco78 profile image
trickydisco78

how does this work with axios?

Collapse
 
pallymore profile image
Yurui Zhang

axios has this thing called CancelToken: github.com/axios/axios#cancellation

it is very similar to AbortController 😄

however I would not use axios in the front end though. fetch is very easy to work with - if you want some of the axios' default behaviors (throw on 4xx/5xx, returns data by default) you can easily wrap fetch in your own helper function to do that.

Collapse
 
peteramd profile image
Peter Anthony Melecio Duot

Why are you not recommending using axios?

Thread Thread
 
pallymore profile image
Yurui Zhang

Because fetch is already pretty good. I'm not against axios - if you know what you are doing. For any new devs I'd highly recommend learning all the basic DOM APIs and utilities instead of trying to find a third party library for everything.

Thread Thread
 
peteramd profile image
Peter Anthony Melecio Duot

Cool, yeah, best tip, learn all basic DOM API, I'm currently doing this one.
Tbh, this is a very underrated tip but very helpful in the long run.

Collapse
 
iquirino profile image
Igor Quirino

A complete guide here: wareboss.com/react-hook-clean-up-u...