ThomasFindlay/react-the-road-to-enterprise

4.4- Request cancellation - CancelToken deprecated

Opened this issue · 0 comments

Hi Thomas,

You have written a really good book! It's awesome.

I write here about 4.4- Axios request cancellation. Right now the CancelToken is deprecated.

Now in the official docs, they advice to use AbortController instead of CancelToken.

Link to the Axios docs: Cancellation

Thank you

const controller = new AbortController();

axios.get('/foo/bar', {
   signal: controller.signal
}).then(function(response) {
   //...
});
// cancel the request
controller.abort()