React lets you use whatever style of data management you want, including mutation. However, if you can use immutable data in performance-critical parts of your application it's easy to implement a fast shouldComponentUpdate() method to significantly speed up your app. Dealing with immutable data in JavaScript is more difficult than in languages designed for it, like Clojure. However, we've provided a simple immutability helper, update(), that makes dealing with this type of data much easier, without fundamentally changing how your data is represented. You can also take a look at Facebook's Immutable.js and React’s Using Immutable Data Structures section for more detail on Immutable.js. You have no way of determining which data has changed since the previous copy has been overwritten. Instead, you need to create a new copy of myData and change only the parts of it that need to be changed.
Features
- It's statically analyzable and it's not much more typing than the mutative version
- Toggle a list of boolean fields from the target object
- Instead of a command object, you can pass a function
- Update a value based on its current one
- Arrays can be indexed into with runtime variables via the ES2015 Computed Property Names feature
- Autovivification, for the auto creation of new arrays and objects when needed