Tree
/ API ReferenceTree
/ API Referenceadd
Adds a new node as a child of a parent node.
Always inserts it at the end of the children list. Use insert if you want to insert it at a specific index.
The Gist
import { create, add } from '@weser/tree'
const newNode = create({
children: [],
})
const newTree = add(tree, 'parent-node-id', 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 added. |
| newNode | T | The node to add. |
Returns
(T) The updated root node with the new node added to the parent node.
© 2024-present Robin Weser. All Rights Reserved.