MCPcopy Create free account
hub / github.com/adobe/react-spectrum / buildTree

Function buildTree

packages/react-stately/src/data/useTreeData.ts:167–190  ·  view source on GitHub ↗
(
    initialItems: T[] | null = [],
    map: Map<Key, TreeNode<T>>,
    parentKey?: Key | null
  )

Source from the content-addressed store, hash-verified

165
166 // oxlint-disable-next-line react/react-compiler
167 function buildTree(
168 initialItems: T[] | null = [],
169 map: Map<Key, TreeNode<T>>,
170 parentKey?: Key | null
171 ) {
172 if (initialItems == null) {
173 initialItems = [];
174 }
175 return {
176 items: initialItems.map(item => {
177 let node: TreeNode<T> = {
178 key: getKey(item),
179 parentKey: parentKey ?? null,
180 value: item,
181 children: null
182 };
183
184 node.children = buildTree(getChildren(item), map, node.key).items;
185 map.set(node.key, node);
186 return node;
187 }),
188 nodeMap: map
189 };
190 }
191
192 function updateTree(
193 items: TreeNode<T>[],

Callers 3

useTreeDataFunction · 0.85
insertFunction · 0.85
updateFunction · 0.85

Calls 3

getChildrenFunction · 0.85
getKeyFunction · 0.50
setMethod · 0.45

Tested by

no test coverage detected