Blog>
Snippets

Batching Actions with `all` Effect in Redux-Saga

Demonstrate how to use the `all` Effect for dispatching multiple actions concurrently within a single saga.
import { all, put } from 'redux-saga/effects';

function* batchedActionsSaga() {
  yield all([
    put({ type: 'ACTION_ONE', payload: 'data for action one' }),
    put({ type: 'ACTION_TWO', payload: 'data for action two' }),
    // Add more actions here if needed
  ]);
}
This code imports the necessary functions from redux-saga and defines a saga called `batchedActionsSaga`. Within this saga, the `all` Effect is used to dispatch multiple actions (`ACTION_ONE` and `ACTION_TWO`) concurrently. Each `put` effect within the `all` array sends an action back to the store. This approach ensures that multiple actions are dispatched at the same time within a single saga execution.