Skip to main content

useTreeActions()

useTreeActions<T>(__namedParameters): TreeActions<T>

Stateless hook that transforms tree data according to actions it takes in nodes and returns a new version of the tree.

Note: each operation returns the whole tree. Future iterations might want to return only the changed portion of the tree.

Type Parameters

T

T

Parameters

__namedParameters

UseTreeActionsOptions<T>

Returns

TreeActions<T>

Object containing all tree manipulation functions

Example

const treeActions = useTreeActions({
nodes: [
{
key: 'root',
label: 'Root',
children: [
{ key: 'child1', label: 'Child 1' },
{ key: 'child2', label: 'Child 2' }
]
}
]
});

// Use tree actions
const updatedTree = treeActions.insertAfter('child1', [
{ key: 'newChild', label: 'New Child' }
]);Type T | undefined is not assignable to type T | undefined. Two different types with this name exist, but they are unrelated.