Answer the question
In order to leave comments, you need to log in
How to pause the saga until a certain value is changed in redux?
There are two requests in different sagas, the first request is to get a token, and the second request is authorization. The first request is always for a token. An authorization request can only be made when the response to the first request has arrived. How can you pause the execution of the saga if the answer to the first request has not yet arrived, and the user has already pressed the login button? (Relatively slow Internet). An indicator that the answer to the first request has come is the token hanging in the editor. And after the arrival of the token, continue execution.
Answers to possible questions:
1. There is no need to combine these two sagas into one
2. Requests are always sent in a strictly defined order (token first, then authorization)
Answer the question
In order to leave comments, you need to log in
You have some kind of action, in response to which the reducer puts the token in the store. In the second saga, you can pause it (the saga) before dispatching this action
const actionWhereTokenReceived = yield take(ACTION_TYPE)
let token = yield select(state => state.path.to.token)
if (!token) {
const actionWhereTokenReceived = yield take(ACTION_TYPE)
token = actionWhereTokenReceived.payload
}
...
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question