mirror of
https://github.com/reactjs/react.dev.git
synced 2026-02-23 20:23:08 +00:00
Update object spread syntax description (#3036)
Removed reference to it being experimental. Changed link to MDN. Mentioned version where it was added.
This commit is contained in:
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user