Immutable Update Patterns
Updating Nested Objects
Common Mistake #1: New variables that point to the same objects
function updateNestedState(state, action) {
let nestedState = state.nestedState;
// ERROR: this directly modifies the existing object reference - don't do this!
nestedState.nestedField = action.data;
return {
...state,
nestedState
};
}Common Mistake #2: Only making a shallow copy of one level
Correct Approach: Copying All Levels of Nested Data
Inserting and Removing Items in Arrays
Updating an Item in an Array
Immutable Update Utility Libraries
Last updated