Are there any side effects of doing a deep copy of state on the appReducer in a Redux application each time a reducer function is called?
I'm asking because the Immutable Update Pattern docs for Redux state that to update a nested object on state, you should shallow copy the nested property and update it.
I'm curious what the side effects would be for just doing a deep copy on state on every action call.
Here is some pseudo code for example
export default function appReducer(state = initialState, action){
let copiedState = JSON.parse(JSON.stringify(state))
switch(action){
case action.UPDATE_NESTED_PROPERTY:
copiedState.thing.anotherThing = somethingNew;
return copiedState;
case action.UPDATE_SOME_OTHER_NESTED_PROPERTY:
copiedState.differentThing.nestedProperty = "updated";
return copiedState;
default:
return state;
}
}
What is bad about the approach of always deep-copying state and then returning it? I haven't seen this done and so I am assuming there is something wrong with it. If state is a massive object, then I'm sure doing a deep copy each time could have issues with performance. But would this cause other issues?