Tree
/ API ReferenceTree
/ API Referenceinsert
Inserts a node at a specific index in a parent node.
The Gist
import { create, insert } from '@weser/tree'
const newNode = create({
children: [],
})
const newTree = insert(tree, 'parent-node-id', 0, newNode)
Parameters
| Parameter | Type | Description |
|---|---|---|
| rootNode | T | The root node of the tree. |
| id | string | The id of the parent node to which the new node will be inserted. |
| index | number | The index at which the new node will be inserted. |
| newNode | T | The node to insert. |
Returns
(T) The updated root node with the new node inserted at the specified index in the parent node.
© 2024-present Robin Weser. All Rights Reserved.