10 Comments
User's avatar
Peter Galiba's avatar

structuredClone() was available more than 3 years ago, but you forgot to mention it. You could also use Object.assign for shallow copy.

Expand full comment
Mikita Aliaksandrovich's avatar

Great point, Peter β€” totally agree! πŸ™Œ

structuredClone() is a solid modern choice, and Object.assign() is still great for shallow copies.

Curious β€” do you use structuredClone() often in production, or still rely on libraries like Lodash for deep cloning?

Expand full comment
Peter Galiba's avatar

I rarely need to clone any data, as I don't mutate it. I map / reduce the data, or make a shallow copy of the changed parts.

Expand full comment
Mikita Aliaksandrovich's avatar

That’s a really clean approach πŸ‘Œ

Keeping data immutable from the start makes cloning almost unnecessary.

Do you mostly work with functional patterns (like map/reduce pipelines) across your projects, or mix in some OOP-style structures too?

Expand full comment
Peter Galiba's avatar

In React, I use functional approach. In Angular and Web Components I use OOP style structures.

Expand full comment
Mikita Aliaksandrovich's avatar

Makes total sense πŸ‘

React’s functional model really encourages immutability, while Angular and Web Components lean more toward OOP patterns by design.

Do you find switching between those paradigms affects how you structure your data flow or think about state management?

Expand full comment
Nikhil Garg's avatar

Such an important topic immutability feels subtle until a tiny mutation breaks something miles away in the app.

Expand full comment
Mikita Aliaksandrovich's avatar

Absolutely! πŸ”₯ It’s one of those things that feels minor until it causes hours of debugging later. Immutability really keeps state changes predictable β€” especially in React apps.

Expand full comment
John's avatar

Really like it! Thanks!

Expand full comment
Mikita Aliaksandrovich's avatar

Thank you!

Expand full comment