You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+8-3
Original file line number
Diff line number
Diff line change
@@ -16,6 +16,7 @@ With `useTree` you can focus on how to render your tree structure and forget abo
16
16
-[useTreeContent()](#usetreecontent)
17
17
-[useTreeLoader()](#usetreeloader)
18
18
-[Rendering a tree](#rendering-a-tree)
19
+
-[Type RootTree<T>](#type-roottreet)
19
20
-[Type Tree<T>](#type-treet)
20
21
-[Type TreeNode<T>](#type-treenodet)
21
22
-[Typescript](#typescript)
@@ -89,7 +90,7 @@ This interface describes the current display state of a tree. It contains two pr
89
90
### useTreeController()
90
91
Get an object that lets you control the current tree (from context). Provides these methods:
91
92
92
-
*`updateState(updater: (oldState: TreeState) => TreeState): void`: update the tree state with your own updater function.
93
+
*`updateState(updater: (oldState: TreeState, tree: RootTree<T>) => TreeState): void`: update the tree state with your own updater function.
93
94
*`setExpanded(id: string, expanded?: boolean): void`: expanded or collapse a tree node.
94
95
*`toggleExpanded(id: string): void`: toggle the expanded state of a tree node.
95
96
*`setActiveId(id: string | null): void`: set which (if any) tree node is active.
@@ -105,13 +106,17 @@ Same as `useTreeController()`, but only for one tree node. You should, for insta
105
106
When used inside the context of a tree, returns the current data of the tree. This can be used if you have several components nested inside your `<TreeContainer>` that all want to display the tree (or parts thereof).
106
107
107
108
### useTreeLoader()
108
-
Use this if you want full control and don't want to use `TreeContainer`. This hook takes a `TreeSource` and a `TreeState` and returns the most up-to-date tree data structure. It will load data from the source if necessary and re-render as that data comes in.
109
+
Use this if you want full control and don't want to use `TreeContainer`. This hook takes a `TreeSource` and a `TreeState` and returns the most up-to-date tree data structure with type `RootTree<T>`. It will load data from the source if necessary and re-render as that data comes in.
109
110
110
111
## Rendering a tree
111
112
When rendering a tree through the `rootElement` of `TreeContainer` or by passing the result of `useTreeLoader()` directly to your component, your component should accept these data types. We will assume that your `TreeSource` is of type `TreeSource<T>` where `T` is your own type that contains your own properties for tree nodes.
112
113
113
114
Root element properties:
114
-
*`tree: Tree<T>`
115
+
*`tree: RootTree<T>`
116
+
117
+
### Type RootTree<T>
118
+
* All properties from `Tree<T>`
119
+
*`allNodes: {[k: string]: TreeNode<T>}`: all currently loaded tree nodes, indexed by ID.
115
120
116
121
### Type Tree<T>
117
122
*`isLoading: boolean`: whether the items are still being loaded.
0 commit comments