Tree
/ API ReferenceTree
/ API Referenceupdate
Updates a node by its id.
Important note
The id can't be overwritten. Use replace instead if you want to replace the node with a new node.
The Gist
import { create, update } from '@weser/tree'
const newNode = create({
children: [],
})
const newTree = update(tree, 'node-id', {
children: [newNode],
})
Parameters
| Parameter | Type | Description |
|---|---|---|
| rootNode | T | The root node of the tree. |
| id | string | The id of the node to update. |
| newNode | Partial<T_BaseNodeInput<T>> | New node data to update the old node with. |
Returns
(T) The updated root node with the node updated.
© 2024-present Robin Weser. All Rights Reserved.