My reducer is as follows:
export const favorites = (state = {
favorites: [],
countFavorite: [],
}, action) => {
switch (action.type) {
case ActionTypes.ADD_FAVORITE:
return { ...state, favorites: action.payload };
case ActionTypes.COUNT_FAVORITE:
return { ...state, countFavorite: [...state.countFavorite, action.payload] };
default:
return state;
}
};
currents I get the following with the old state and the new state:
I would like for the new object to override the existing object with the same key in the array, any help would be very appreciated