Loading...
const copy = JSON.parse(JSON.stringify(state));
copy.createdAt.getTime();const copy = structuredClone(state);
copy.createdAt.getTime();The JSON round trip turns Date into a string; structuredClone() keeps Date, Map, Set and circular references.
structuredClone(), not JSON.parse(JSON.stringify()), which loses Date, Map and Set.No, functions and DOM nodes throw a 'DataCloneError'. Remove them or copy those fields by hand.
Spread makes a shallow copy, so nested objects are shared. structuredClone() copies every level.
No, getters are read into plain values, and class instances become plain objects without their methods.