I want to clone an obj with some react elements inside. When I clone the obj
with JSON.parse(JSON.stringify(obj)). It removes $$typeof: Symbol(react.element).
const elm = <span>A Simple Span</span>
console.log(elm)
const copyOfElm = JSON.parse(JSON.stringify(elm))
console.log(copyOfElm);
I want to know how to clone in a way that it does not remove the property.
React.cloneElement?JSON.parse(JSON.stringify(something))is not a reliable way to clone objects. It works sometimes, but as you've found it doesn't work all the time.JSON.stringifyignores allSymbolproperties.