Tree
/ API Reference
Tree
/ API Reference

replace

Replaces a node by a new node.

The Gist

import { create, replace } from '@weser/tree'

const newNode = create({
  children: [],
})

const newTree = replace(tree, 'node-id', newNode)

Parameters

ParameterTypeDescription
rootNodeTThe root node of the tree.
idstringThe id of the node to replace.
newNodeTThe new node to replace the old node with.

Returns

(T) The updated root node with the node replaced by the new node.

On this page