Usage
Tree
component is used to display hierarchical data. Tree
component
has minimal styling by default, you can customize styles with Styles API.
- src
- node_modules
- package.json
- tsconfig.json
Data prop
Data passed to the data
prop should follow these rules:
- Data must be an array
- Each item in the array represents a node in the tree
- Each node must be an object with
value
andlabel
keys - Each node can have
children
key with an array of child nodes - The
value
of each node must be unique
Valid data example:
Invalid data example:
Data type
You can import TreeNodeData
type to define data type for your tree:
renderNode
Use renderNode
prop to customize node rendering.
renderNode
function receives an object with the following properties as a single argument:
- src
- node_modules
- package.json
- tsconfig.json
useTree hook
useTree
hook can be used to control selected and expanded state of the tree.
The hook accepts an object with the following properties:
And returns an object with the following properties:
You can pass the value returned by the useTree
hook to the tree
prop of the Tree
component
to control tree state:
- src
- node_modules
- package.json
- tsconfig.json
Checked state
Tree
can be used to display checked state with checkboxes.
To implement checked state, you need to render Checkbox.Indicator
in the renderNode
function:
- src
- node_modules
- package.json
- tsconfig.json
Example: files tree
- src
- node_modules
- package.json
- tsconfig.json