Async
Async children loading
react-tree-multi-select supports lazy loading of node children via the onLoadChildren prop.
Children are loaded on demand when the user expands a node that declares it has children (hasChildren: true).
Async children loading
Expansion and loading behavior
- A node is rendered with
hasChildren: true - The user expands the node
- The component calls
onLoadChildren(nodeId) - The returned children are merged into the tree
- The node is expanded and rendered with its loaded children
Selection behavior
Uncontrolled mode
When the component manages its own selection state (selectedIds is not provided):
- If a selected parent node loads children asynchronously, those children are automatically selected
- A single
onNodeChangecallback is triggered after the children are loaded and auto-selected, and it is invoked for the parent node that was expanded
Controlled mode
When selectedIds is provided:
- The component does not auto-select asynchronously loaded children
- The parent application is responsible for updating selectedIds
- This guarantees that the external state remains the single source of truth
NOTE
onLoadChildrenis called only once (if successful) per node- The component tracks loading state internally
- Node toggle are rendered when
hasChildrenistrue, even if children are not yet loaded - Children provided via initial data are treated as already loaded