In my reducer I am trying to merge current state with value pased trought action. But problem is that merge operation remove object atribut instead of updating it. I am using:
on(WineActions.SetCurrentWine, (state, data) => {
const newState = deepCopy(state);
return {
...newState,
currentWine: {...newState.currentWine, ...data}
};
}),
...
export function deepCopy(state) {
return JSON.parse(JSON.stringify(state));
}
Thank to all of you!!!!
Edit: I did went trough whole reducer and find out that problem was initialize action... I hate that I do not know why merge does not work but it is working now...
The first thing - never do deep copy, only update the value you need.
if you want data
to replace currentWine
, do like that.
on(WineActions.SetCurrentWine, (state, data) => {
return {
...state,
currentWine: data,
};
}),
and nothing else.