Browse Source

Update object spread syntax description (#3036)

Removed reference to it being experimental. Changed link to MDN. Mentioned version where it was added.
main
Cory House 5 years ago
committed by GitHub
parent
commit
d58e9d0ed6
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 4
      content/docs/optimizing-performance.md

4
content/docs/optimizing-performance.md

@ -371,7 +371,7 @@ function updateColorMap(colormap) {
`updateColorMap` now returns a new object, rather than mutating the old one. `Object.assign` is in ES6 and requires a polyfill.
There is a JavaScript proposal to add [object spread properties](https://github.com/sebmarkbage/ecmascript-rest-spread) to make it easier to update objects without mutation as well:
[Object spread syntax](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Spread_syntax) makes it easier to update objects without mutation as well:
```js
function updateColorMap(colormap) {
@ -379,6 +379,8 @@ function updateColorMap(colormap) {
}
```
This feature was added to JavaScript in ES2018.
If you're using Create React App, both `Object.assign` and the object spread syntax are available by default.
When you deal with deeply nested objects, updating them in an immutable way can feel convoluted. If you run into this problem, check out [Immer](https://github.com/mweststrate/immer) or [immutability-helper](https://github.com/kolodny/immutability-helper). These libraries let you write highly readable code without losing the benefits of immutability.

Loading…
Cancel
Save