There is an action to update an item:
reducers: {
ITEM_UPDATED: (state) => {
...someCode...
}
}
Then it becomes necessary to update not one element, but several, which solution would be more correct here:
- Create thunk for updating several elements and from there call the update of each one by one:
const updateItems = () => (dispatch) => {
const items = axios.get('...');
items.forEach(( item ) => dispatch(ITEM_UPDATED, item))
}
- Move the handler for updating the element into a separate function and reuse it.
const handleItemUpdated = (state) => {
...
}
reducers: {
ITEM_UPDATED: (state, item) => handleItemUpdated(state, item);
ITEMS_UPDATED: (state, items) => {
items.forEach(( item) => handleItemUpdate(state, item));
}
}