structuredClone() and Immutable Update Patterns in WordPress JavaScript
structuredClone(): real deep copies in WordPress JavaScript The spread operator copies one level: { ...state } is a new object, but its nested objects are shared with the old one. A change “in the copy” changes the original, and an undo function restores nothing. The classic workaround JSON.parse( JSON.stringify( obj ) ) makes a deep…
Details