Middleware that allows to dispatch an array of actions
yarn add redux-dispatch-batch-middleware
or (if you are not using Yarn, but hope you do 😉)
npm i redux-dispatch-batch-middleware
In place where your createStore
lives:
import { createStore, applyMiddleware } from 'redux';
import dispatchBatchMiddleware from 'redux-dispatch-batch-middleware';
const createStoreWithMiddlewares = applyMiddleware(
// ... all your middlewares
dispatchBatchMiddleware,
)(createStore);
and now you can dispatch your actions like this:
dispatch([
oneAction(),
anotherOneAction(someArgs),
andAllOthersThatYouNeed(),
]);
🎉
p.s. And of course you can still dispatch like this:
dispatch(something());