Tree
/ API Reference
Tree
/ API Reference

move

Moves a node to a new parent node at a specific index.
If no index is provided, the node is moved to the end of the children list.

The Gist

import { move } from '@weser/tree'

const newTree = move(tree, 'node-id', 'parent-node-id', 0)

Parameters

ParameterTypeDefaultDescription
rootNodeTThe root node of the tree.
idstringThe id of the node to move.
parentIdstringThe id of the new parent node to which the node will be moved.
indexnumber?children.lengthThe index at which the node will be moved.

Returns

(T) The updated root node with the node moved to the new parent node at the specified index.

On this page