DEV Community

Discussion on: useCancelToken: a custom React hook for cancelling Axios requests

Collapse
 
tmns profile image
tmns

Hey there Diko!

In your code the cancel token would go within that same config object. So something like:

api({
  method: 'POST',
  url: URL,
  params: {
    'user-token': Token,
  },
  cancelToken: source.token
});
Enter fullscreen mode Exit fullscreen mode

Note however that if you're using at least Axios v0.22.0 the cancel token API has been deprecated in favor of a fetch-like abort controller.