There are ways to achieve the goal:
The classic way:
usually: Actions describe the fact that something happened , but do not indicate how the state of the application changes in response. This is the work of gearboxes. It also means that actions are not setters .
That way, you can describe what happened and accumulate the changes and submit one action something like this:
const multipleAddProp = (changedProps) =>({ type:'MULTIPLE_ADD_PROP', changedProps });
And then respond to the action in the gearbox:
const geo=(state,action)=>{ ... switch (action.type){ case 'MULTIPLE_ADD_PROP': // apply new props ... } }
Another way when redrawing is critical:
then you can consider limiting the components that can be overridden when the state changes. For example, you can use shouldComponentUpdate to check whether a component should be displayed or not. You can also use reselection so as not to redraw the connected components after calculating the derived data ...
Custom way: redundant batch action
It works a bit like a transaction.
In this example, subscribers will be notified once:
import { batchActions } from 'redux-batched-actions'; const multiGeoChanges=(...arrayOfActions)=> dispatch => { dispatch( batchActions(arrayOfActions) ); }
source share