mirror of
https://github.com/facebook/react.git
synced 2025-11-01 09:12:30 +00:00
Fix object spread operator (#8378)
Object spread operator performs shallow copy of object's arguments, so it should be placed before new properties are assigned.
This commit is contained in:
committed by
Dan Abramov
parent
65f9d2ae9e
commit
91676a619a
@@ -226,7 +226,7 @@ var newPlayer = Object.assign({}, player, {score: 2});
|
||||
// Now player is unchanged, but newPlayer is {score: 2, name: 'Jeff'}
|
||||
|
||||
// Or if you are using object spread, you can write:
|
||||
// var newPlayer = {score: 2, ...player};
|
||||
// var newPlayer = {...player, score: 2};
|
||||
```
|
||||
|
||||
The end result is the same but by not mutating (or changing the underlying data) directly we now have an added benefit that can help us increase component and overall application performance.
|
||||
|
||||
Reference in New Issue
Block a user