If your object is "deep" because of real nested dependencies, then you should ask why your user would need to mutate it in the first place. If they want to change its internal structure then this is indicative of a code smell because your object is too big and the user cannot accomplish their goal by calling functions exposed by your API.
There was a phase in the JS ecosystem a few years ago where everything absolutely had to be immutable. This was, IMO, a horrible side effect of react developers optimizing their props for diffing during reconciliation. Libraries like immer and redux produced a lot of this zealotry.
I understand the purism appeal of "immutable everything," and I won't say it has no application, but it has been dogmatically over-applied to the point that you have people googling how to deep clone their config object with a nested function assignment because they're scared of passing a mutable object, and oh my god what if my user mutates it?
Also your object won't be that complicated in the first place, they would be treated as plain data object like struct or record. And you would not use those advanced features in objects(Not needed).
My most common use is for delta detection and json-patch based APIs.
I keep the original entity and allow the user to modify a clone.
When it's time to sync, I compare it to the original to generate a patch set to send to the server with json-patch [1] semantics.
I highly recommend the excellent fast-json-patch library [2] that makes this process a breeze.
Actually, I use its deepClone method outside of json-patch scenarios, it's so well implemented.
How is that a smell? or how would you refactor it?
Yes, sometimes you will want a deep copy. These are fewer and further between than online reading about it would have you think.
With setState in React, you don't necessarily have to copy to update the state. setState merges the partial object you provide with the current state.
https://reactjs.org/docs/state-and-lifecycle.html#state-upda...
In Redux reducers, however, you need a full copy.