A lightweight React component for efficiently rendering large tree structures (millions of nodes) built on top of react-window. Current stable version is v3.0.0 (released 2023), which requires React 18+. Release cadence is irregular; v3.0.0 consolidated changes from a long beta, with v4.0.0 planned. Key differentiators: uses a generator-based treeWalker for flexible tree building, supports both fixed-size and variable-size items, and ships TypeScript definitions. Alternatives like react-virtualized-tree are heavier or less maintained.
npm install react-vtreeVerified import paths — ran on the pinned version, not inferred.
A complete minimal example: defining a tree structure, implementing the treeWalker generator, creating a Node component, and rendering a FixedSizeTree.
Rewrite treeWalker as a generator function. See documentation for the new pattern.
Use recomputeTree with opennessState object instead of direct state mutations.
Ensure `isOpenByDefault` is present in the yielded data.
Use `style as React.CSSProperties` if needed.
Replace `toggle` with `setOpen` and call `setOpen(!isOpen)` to toggle.
Upgrade to React 18+ or use react-vtree v2.x (requires React 16.8+).
Ensure treeWalker is defined as a generator function: function* treeWalker() { ... }Add `isOpenByDefault: true` (or false) to all yielded data objects.
Pass a valid treeWalker function as the `treeWalker` prop to the Tree component.
Destructure setOpen and do not pass it to the DOM element (e.g., inline style only passes style and other needed props).