Answer the question
In order to leave comments, you need to log in
How to put an action in a callback using redux saga and if you need an event channel?
Good afternoon, redux saga gurus) I just started to master it ...
There was a task to make authentication on the site using VK OpenApi. At the same time, redux saga is used for logic. For this, the *someSaga saga was made in which vk.api.call is called, in the callback of which it would be nice to call yield put(someAction()), but this is impossible, because callback is not a generator.
I read that you can use the redux saga event channel: I made a separate function someFunction, where I return an eventChannel (as described in the redux saga docs and in it I do emit (data) of the data that vk.api returned to me), then I call it in the previously created saga with using
const callVkChannel = yield call(()=>someFunction())
const data = yield take(callVkChannel ) (and the authorization data is successfully written to data)
but at the same time, all the other actions that are sent using put in other sagas somehow get there sideways.
The question is why is that?
Answer the question
In order to leave comments, you need to log in
There was a similar problem. I decided that the easiest way would be to pull store.dispatch directly, and not through put.
1. Pass store.dispatch to the root saga:
const sagaMiddleware = createSagaMiddleware();
const store = configureStore({
reducer: {
app: VkAppReducer,
},
middleware: [
sagaMiddleware,
],
});
sagaMiddleware.run(rootSaga, store.dispatch);
function* rootSaga(dispatch) {
yield spawn(ChildSaga, dispatch);
}
const params: MethodParams = {
group_id: 1,
access_token: access_token,
onProgress: (s: string) => {
dispatch(setProgress(s));
},
};
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question