Why should objects in Redux be immutable? I know that some frameworks such as Angular2 will use onPush and can take advantage of immutability to compare states of views for
The following benefits of immutability are mentioned in Redux documentation:
- Both Redux and React-Redux employ shallow equality checking. In particular:
- Redux's combineReducers utility shallowly checks for reference changes caused by the reducers that it calls.
- React-Redux's connect method generates components that shallowly check reference changes to the root state, and the return values from the mapStateToProps function to see if the wrapped components actually need to re-render. Such shallow checking requires immutability to function correctly.
- Immutable data management ultimately makes data handling safer.
- Time-travel debugging requires that reducers be pure functions with no side effects, so that you can correctly jump between different states.