From the course: React: State Management (2019)

Unlock the full course today

Join today to access over 22,500 courses taught by industry experts or purchase this course individually.

Immutability out of the box

Immutability out of the box - React.js Tutorial

From the course: React: State Management (2019)

Start my 1-month free trial

Immutability out of the box

- [Instructor] Immutability is one of the greatest draws of Redux. It's what allows us to easily implement undo and redo functionality and what allows us to replay our app through the course of a user experience. Immutability in programming means that we don't change something after it's created. With regards to Redux, it means we never mutate state directly. For example, if we wanted to change state we wouldn't manipulate a property directly. We'd instead return a new state with the modified property. This also means that you can't use functions like pop or push directly when updating an array, for example. You always need to extend the current object. For example, using the ES6 spread operator. And remember, this applies to both React and Redux state. Immutability is what allows us to undo and redo. If we ever want to undo an action, store all versions of the state and return the previous version of the state before the current one. It's also what makes Redux predictable. Using…

Contents