Skip to content

Commit 5f61b7a

Browse files
committed
docs: more guides
1 parent 64b7b19 commit 5f61b7a

File tree

7 files changed

+41
-17
lines changed

7 files changed

+41
-17
lines changed

packages/docs/docs/recipes/0-handling-expensive-components.mdx

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,25 @@ category: recipe
77

88
import { DemoBox } from "../../src/components/demo/demo-box";
99

10+
Sometimes, rendering tree items can be expensive. This can cause slow usage of the Tree react component,
11+
since all items are rendered as part of a single flat list, and mutations to the displayed tree structure,
12+
such as expanding or collapsing items or changing the tree will trigger a re-render of all items.
13+
1014
<DemoBox stories={["react-guides-render-performance-slow-item-renderers--slow-item-renderers"]} />
1115

16+
Memoizing the individual tree item render methods can help reduce the performance impact of rendering
17+
expensive tree items. This can be done using the `React.memo` function, which will only re-render the
18+
component if the props have changed.
19+
20+
`React.memo` will only rerender its contents if any of its props have changed. Headless Tree doesn't
21+
memoize props generated with `tree.getContainerProps()` and `item.getProps()` by default, and will
22+
create new props during each render. By including the [Prop Memoization Feature](/features/propmemoization)
23+
however, these props will be memoized automatically, making memoization of render items feasible.
24+
25+
Note that, in the sample below, expanding or collapsing individual items is much more efficient than
26+
in the sample above, since now only those items that actually change will be rerendered.
27+
1228
<DemoBox stories={["react-guides-render-performance-memoized-slow-item-renderers--memoized-slow-item-renderers"]} />
29+
30+
You can further improve performance on large trees by making use of Virtualization, which is explained in
31+
the [Virtualization Guide](/recipe/virtualization).

packages/docs/docs/recipes/1-virtualization.mdx

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,25 @@ category: recipe
77

88
import { DemoBox } from "../../src/components/demo/demo-box";
99

10+
Large trees can have a significant impact on render and usage performance, and cause slow
11+
interactions. Virtualization is a concept, where the performance hit of a very large list of items
12+
is mitigated by only rendering the items that are currently visible in the viewport.
13+
14+
While this is not trivial to do with nested structures like trees, Headless Tree makes this
15+
easy by flattening the tree structure and providing the tree items as flat list. Virtualization
16+
is not a included feature of Headless Tree, but you can easily pass this flat list to any virtualization
17+
library of your choice, and use that to create a tree that only renders the visible items.
18+
19+
In the sample below, `react-virtual` is used to virtualize the tree and render 100k items while
20+
still being performant in rendering and interaction.
21+
1022
<DemoBox stories={["react-scalability-basic-virtualization--basic-virtualization"]} />
23+
24+
:::warning
25+
26+
You likely will want to use proxified item instances instead of static item instances when
27+
using trees with many items. Read this guide to learn more about [Proxy Item Instances](/recipe/proxy-instances).
28+
You can use them by setting the `instanceBuilder` tree config option to [`buildProxiedInstance`](/api/core/function/buildProxiedInstance),
29+
a symbol that you can import from `@headless-tree/core`.
30+
31+
:::
File renamed without changes.
File renamed without changes.

packages/docs/docs/recipes/4-multiple-trees.mdx

Lines changed: 0 additions & 8 deletions
This file was deleted.

packages/docs/docs/recipes/5-plugins.mdx

Lines changed: 0 additions & 8 deletions
This file was deleted.

packages/sb-react/src/scalability/virtualization.stories.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ const meta = {
3232
},
3333
args: {
3434
itemsPerLevel: 10,
35-
openLevels: 2,
35+
openLevels: 4,
3636
useProxyInstances: true,
3737
},
3838
} satisfies Meta;

0 commit comments

Comments
 (0)