DEV Community

Discussion on: React useEffect cleanup: How and when to use it

Collapse
 
kavehkarami profile image
Kaveh Karami • Edited

Thanks for the solution on Axios request.
I have a question.
I'm using an instance of Axios and in this instance, you cant be able to use instanceAxios.CancelToken.source() so I gotta import Axios too.
is there another way to use CancelToken.source() in the instance of Axios like instanceAxios.CancelToken.source()?

Collapse
 
otamnitram profile image
Martín Mato

As far as I know axios by design, cancelToken won't be part of the instance. You may be able to do something similar to this.

const axios = require('axios');
const source = axios.CancelToken.source();
const instance = axios.create();
instance.get('/foo', { cancelToken: source.token });
Enter fullscreen mode Exit fullscreen mode