Skip to content

Commit

Permalink
Update UsingObjectSpreadOperator.md (#3367)
Browse files Browse the repository at this point in the history
I think this warning on using the Object spread operator to clone objects is important. While, good style would encourage the use of flat objects in the reducer, not everyone is going to do that. Using the spread syntax in a reducer on a multidimensional data structure is opening up the door to state mutation.
  • Loading branch information
mtpetros authored and timdorr committed Aug 2, 2019
1 parent 42474f3 commit 14efbe1
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions docs/recipes/UsingObjectSpreadOperator.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,3 +64,6 @@ While the object spread syntax is a [Stage 4](https://github.com/tc39/proposal-o
"plugins": ["@babel/plugin-proposal-object-rest-spread"]
}
```
> ##### Note on Object Spread Operator
> Like the Array Spread Operator, the Object Spread Operator creates a [shallow clone](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Spread_syntax#Spread_in_object_literals) of the original object. In other words, for multidimensional source objects, elements in the copied object at a depth greater than one are mere references to the source object (with the exception of [primitives](https://developer.mozilla.org/en-US/docs/Glossary/Primitive), which are copied). Thus, you cannot reliably use the Object Spread Operator (`...`) for deep cloning objects.

0 comments on commit 14efbe1

Please sign in to comment.