I've been trying to work this out, making some research and breaking my head, but I've still haven’t figured this out.
So I have a React + Redux application. At some point, the application renders multiple same components
return (
<MyComponent id={1} path={path} />
<MyComponent id={2} path={path} />
<MyComponent id={3} path={path} />
)
Here, MyComponent is connected to redux and makes an API call using Saga. I tried to implement a mechanism to be able to cancel those API request with something like this:
export function* watchMyRequest(action) {
const task = yield fork(getRequestSaga, action);
yield take(RESET_REQUEST_DATA);
yield cancel(task);
}
Each time path
changes, I dispatch an action for RESET_REQUEST_DATA
which should cancel my saga. The problem is that as I have multiple identical components, they will all call on the cancel action.
My question is, how can I manage just to call on an specific cancel using Sagas?
question from:
https://stackoverflow.com/questions/65928541/cancel-saga-when-multiple-components-use-it 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…