Tree
/ API Reference
Tree
/ API Reference

update

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

ParameterTypeDescription
rootNodeTThe root node of the tree.
idstringThe id of the node to update.
newNodePartial<T_BaseNodeInput<T>>New node data to update the old node with.

Returns

(T) The updated root node with the node updated.

On this page