Tree
/ API ReferenceTree
/ API Referencemove
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
| Parameter | Type | Default | Description |
|---|---|---|---|
| rootNode | T | The root node of the tree. | |
| id | string | The id of the node to move. | |
| parentId | string | The id of the new parent node to which the node will be moved. | |
| index | number? | children.length | The 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.
© 2024-present Robin Weser. All Rights Reserved.