I would need some help on Redux immutable array state. I am getting array of objects from actions and passing it to reducer. In my reducer file I am immutating the array and it gives me a new copy every time.
The problem that I am facing is it always gives me previous + new array (Which is correct) like keeps adding new array with new state and I need the last update array only. Because that I have to pass to react.
export default (state = {}, action) => {
switch (action.type) {
case EVT.LB_FOLLOWING_CHANGE:
return [
...state,
action.payload
];
break;
default:
return state;
}
};
return [ ...state, action.payload ]toreturn [ action.payload ]....stateat the beginning of your return, you are first returning the current value of the state, and then appending the action.payload. That's why you are always getting your previous plus your new array.