I am learning React-Redux, and Recently I found about Immutability Helpers in React, Just Want to Know if it is good Practice to use Immutability Helpers in React Redux Operations and if yes/no, then why, I appreciate any detailed explanation, Thank You.
-
1https://redux-toolkit.js.org/ uses immer.js in its `createReducer` and `createSlice` methods. In my opinion this makes working with redux easier, as there is much less code to read/write. – ksav Jul 15 '21 at 06:15
-
Okay, I am new to react, But gonna See that also, thanks! – Milan jotva Jul 15 '21 at 11:57
1 Answers
From the Immutability Helpers docs:
update()
provides simple syntactic sugar around this pattern to make writing this code easier.
While the syntax takes a little getting used to (though it’s inspired by MongoDB’s query language) there’s no redundancy, it’s statically analyzable and it’s not much more typing than the mutative version.
It's an advanced solution than Object.assign()
and spread operator (...
).
There is also a more advanced solution for updating state. - immerjs
You don't need to care and write too much shallow copy code to update the nested states.
With the increasing performance of machine devices, the performance issues of reading and writing states can be almost disregarded for general applications. Priority should be given to improving development efficiency, reducing code redundancy, and improving code reusability, readability, maintainability, and extensibility.
Immutability Helpers and immerjs and other similar libraries are designed to solve this problem.

- 88,126
- 95
- 281
- 483
-
-
@Milanjotva Performance benchmark testing. See https://immerjs.github.io/immer/performance/ and https://github.com/linq2js/immhelper/blob/HEAD/benchmarks-result-03.txt – Lin Du Jul 15 '21 at 01:52
-
-
-