How do you complete multiple steps without knowing which one is sent first?
How can I wait for both ACTION_A and ACTION_B to be sent without knowing which one was sent first?
I tried const result = yield take([ACTION_A, ACTION_B])
but result
- this is only the first action dispatched whereas I need both actions.
I have tried const {a, b} = yield race({a: yield take(ACTION_A), b: yield take(ACTION_B)})
but if a
defined is b
not.
Remember that I can't just yield take(ACTION_A); yield take(ACTION_B)
because I don't know which one comes first.
source to share
You can use an assistant all
. all
creates an effect description that instructs middleware to run multiple effects in parallel and wait for all of those actions to complete.
Your code might look like:
function* mySaga() {
const [actionA, actionB] = yield all([
take(ACTION_A),
take(ACTION_B),
])
}
Hope my answer was helpful.
source to share