Ensuring Immutability
Learn how to ensure immutability in Redux.
We'll cover the following
Here are a number of methods and tools that strive to provide immutability.
Libraries
Deep Freeze
One approach is to use libraries like deep-freeze that will throw errors every time someone tries to mutate a frozen
object.
While JavaScript provides an Object.freeze()
method, it only freezes the object it is applied to, not its children objects. Deep-freeze
and similar libraries perform nested freezes and method overrides to better catch such errors.
We can also use libraries that manage truly immutable objects. Although they add additional dependencies to the project, they ensure true immutability, offer cleaner syntax to update collections, support nested objects, and provide performance improvements on extensive data sets.
Get hands-on with 1400+ tech skills courses.