I need to save the data from the array to Saga (redux-saga). But I have an array that needs to maintain its sequence.
I add a new item in the action to which I pass "text" and "ID" after which I need to put a new item. As well as the reducer, which combines the first piece of the array before the index + new element + the second piece of the array after the index.
How can I save this array in local storage in saga, if the array is combined into a reducer, and saga is a middleware and is called before the reducer?
(Save is necessary in the Saga, it is a prerequisite, I know that this can be done by using the subscriber's)
The idea is that I can combine and save the array in the Saga, but then reducer will not do anything and I will transfer the processing status in middleware It's not very good What i need to write in saga?
reducer.js
switch (action.type) {
case ADD_NEW_ELEMENT:
return [
...state.slice(0, action.afterIndex + 1),
action.text,
...state.slice(action.afterIndex + 1)
];
default:
return state;
}
action.js
return {
type: ADD_NEW_ELEMENT,
text,
afterIndex
};