Tree
/ API Reference
Tree
/ API Reference

add

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

ParameterTypeDescription
rootNodeTThe root node of the tree.
idstringThe id of the parent node to which the new node will be added.
newNodeTThe node to add.

Returns

(T) The updated root node with the new node added to the parent node.

On this page