Tree
/ API Reference
Tree
/ API Reference

clone

Clones a node and all its children with new ids.

The Gist

import { clone } from '@weser/tree'

const clonedNode = clone(tree, 'node-id')

Parameters

ParameterTypeDescription
rootNodeTThe root node of the tree.
idstringThe id of the node to clone.

Returns

(T | null) A new node with the same structure as the original node, but with a new id. Returns null if no node with the given id was found.

On this page