Mar 9, 2021
Basically, spread operator deep copies the data if it is not nested.
For nested data, it deeply copies the topmost data and shallow copies of the nested data.
For example:
const oldObj = {a: {b: 2}, c: 5};
const newObj = {...oldObj};
newObj.a.b = 10; // change in nested
newObj.c = 20; // not nested
oldObj; //{a: {b: 10}, c: 5}; // b also changed
newObj; //{a: {b: 10}, c: 20};
oldObj.a === newObj.a;
//true - Shallow copy( same reference)
Hope this clarifies your concern Alfredo!