deepClone
Create a deep copy of objects and arrays, handling nested structures safely.
Installation
npx react-usekit@latest init
Select: utils → TypeScript or JavaScript → path -> deepClone
Usage
import { deepClone } from "./utils/deepClone";
function App() {
const original = { name: "John", hobbies: ["reading", "coding"] };
const cloned = deepClone(original);
return (
<div>
<p>Original: {JSON.stringify(original)}</p>
<p>Cloned: {JSON.stringify(cloned)}</p>
</div>
);
}
API
Parameters
Parameter | Type | Description |
---|---|---|
obj | T | The object or array to clone |
Returns
Type | Description |
---|---|
T | A deep copy of the input object |