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. Then you can compare the old copy of `myData` with the new one in `shouldComponentUpdate()` using triple-equals:
```js
var newData = deepCopy(myData);
const newData = deepCopy(myData);
newData.x.y.z = 7;
newData.a.b.push(9);
```
@ -44,7 +44,7 @@ newData.a.b.push(9);
Unfortunately, deep copies are expensive, and sometimes impossible. You can alleviate this by only copying objects that need to be changed and by reusing the objects that haven't changed. Unfortunately, in today's JavaScript this can be cumbersome:
```js
var newData = extend(myData, {
const newData = extend(myData, {
x: extend(myData.x, {
y: extend(myData.x.y, {z: 7}),
}),
@ -61,7 +61,7 @@ While this is fairly performant (since it only makes a shallow copy of `log n` o
```js
import update from 'react-addons-update';
var newData = update(myData, {
const newData = update(myData, {
x: {y: {z: {$set: 7}}},
a: {b: {$push: [9]}}
});
@ -85,16 +85,16 @@ The `$`-prefixed keys are called *commands*. The data structure they are "mutati
@ -208,8 +208,8 @@ If you're using Create React App, both `Object.assign` and the object spread syn
Immutability makes tracking changes cheap. A change will always result in a new object so we only need to check if the reference to the object has changed. For example, in this regular JavaScript code:
```javascript
var x = { foo: "bar" };
var y = x;
const x = { foo: "bar" };
const y = x;
y.foo = "baz";
x === y; // true
```
@ -217,9 +217,9 @@ x === y; // true
Although `y` was edited, since it's a reference to the same object as `x`, this comparison returns `true`. You can write similar code with immutable.js: