Last active
June 22, 2019 14:25
-
-
Save shapkarin/5dfb7dd134fca1e51fdcef1fd24a8adf to your computer and use it in GitHub Desktop.
Close axios with saga worker cancellation. thank's to that issue https://github.com/redux-saga/redux-saga/issues/651
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import axios, { CancelToken } from 'axios'; | |
import { CANCEL } from 'redux-saga'; | |
export const fetchAutocomplete = () => { | |
const url = 'some/url'; | |
const source = CancelToken.source(); | |
const request = axios.get(url, { cancelToken: source.token }); | |
request[CANCEL] = () => source.cancel(); | |
return request; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment