News for hackers. Stuff that matters.
Re:React Common Tools and Practices: State Management Overview by IceHegel on Wednesday March 10, 2021 @11:13AM (#26412759)
This will work but isn't advised.

- Bad: newX = JSON.parse(JSON.stringify(x))

- Slightly Better: newX = lodash.cloneDeep(x)

- Best(using immer): newX = produce(x, draftX => {draftX[1].done = true})

I don't know how JavaScript engines actually assign memory, but I think of object references in JavaScript like pointers in C. If you deep clone you're copying way more than you need, mallocing giant blocks of memory for duplicated data. Libraries like immer(the best) and immutable.js will only copy what you changed, which saves time and memory.

There are no comments on this comment yet.