News for hackers. Stuff that matters.
Re:Deep Cloning Objects in JavaScript, the Modern Way by compacct27 on Thursday December 21, 2023 @07:20PM (#38729135)
React needs a new object for its hooks when you change them. We need to modify those objects, so deepClone + direct mutation on the clone bypasses a lot of annoying immutable object creation bs. ppl just destructure the whole thing anyways, which is actually also pretty slow
Re:Deep Cloning Objects in JavaScript, the Modern Way by chatmasta on Thursday December 21, 2023 @08:25PM (#38729743)
React hooks don't need to add the entire object to their dependency array; they can specify only the properties that are actually dependencies of the logic contained in the hook.
Re:Deep Cloning Objects in JavaScript, the Modern Way by jcparkyn on Thursday December 21, 2023 @10:20PM (#38730592)
You should check out immer for that use case ("modifying" an immutable object with imperative code).