Redux-saga call multiple functions/actions Code Answer

I want to call two different functions in my sagas with different actions:

export default function* () {
  yield takeLatest(actionTypes.ADD_ACCOUNT, addAccountSaga);
  yield takeLatest(actionTypes.GET_WALLET, getBalanceSaga);
}

I’ve read some articles and I tried to put them in array like this :

yield [(
  takeLatest(actionTypes.ADD_ACCOUNT, addAccountSaga), 
  takeLatest(actionTypes.GET_WALLET, getBalanceSaga)
)];

But sadly it did not work, I also tried this method:

yield * takeLatest(actionTypes.ADD_ACCOUNT, addAccountSaga);
yield * takeLatest(actionTypes.GET_WALLET, getBalanceSaga);

I also putted console.log in one of the functions to be sure if its working or not but console.log did not worked which means function is not being called

But this also did not work. Could you help me to solve this problem?

Answer

You can use all effect combinator

Creates an Effect description that instructs the middleware to run multiple Effects in parallel and wait for all of them to complete

yield all([
  takeLatest(actionTypes.ADD_ACCOUNT, addAccountSaga), 
  takeLatest(actionTypes.GET_WALLET, getBalanceSaga)
])

Related Posts

© No Copyrights, All Questions are retrived from public domain.
Tutorial Guruji