How does this works with redux and redux-saga? is it advisable to clean up on every fetch?
If you are using takeLatest - redux-saga already cancels the effect for you. If you want to abort the request as well, try this:
takeLatest
redux-saga
export function* requestAPI(action) { const abortController = new AbortController(); try { const response = yield call(fetch, url, { ...fetchParams, signal: abortController.signal }); } finally { if (yield cancelled()) { abortController.abort(); } } }
If you want to cancel sagas manually, check out their cancellation documentation: redux-saga.js.org/docs/advanced/Ta...
or even better - you could write your custom fetchAPI, which would look something like this
import axios, { CancelToken } from 'axios' import { CANCEL } from 'redux-saga' export default function fetchAPI(url) { const source = CancelToken.source() const request = axios.get(url, { cancelToken: source.token }) request[CANCEL] = () => source.cancel() return request }
link: github.com/redux-saga/redux-saga/i...
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
How does this works with redux and redux-saga? is it advisable to clean up on every fetch?
If you are using
takeLatest
-redux-saga
already cancels the effect for you. If you want to abort the request as well, try this:If you want to cancel sagas manually, check out their cancellation documentation:
redux-saga.js.org/docs/advanced/Ta...
link: github.com/redux-saga/redux-saga/i...