I was just trying to clone a parameter and after some manipulation update the redux state. But some unwanted value is updating , cause the clone copied the reference of the object also. Normally we try to assign a value of an object to another via ,
let something= sourceObject
But, it can mutate the source object sometime, if the object is nested. Another way of doing the clone is,
let something= {...sourceObject}
Still same result. Also tried,
let something= Object.assign({},sourceObject)
No change of the scenario. Then, lodash came to rescue,
let something= _.cloneDeep(sourceObject);
Now, it's just cloning the object without mutating it.
Top comments (0)