@@ -7,6 +7,25 @@ category: recipe
77
88import { 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 ) .
0 commit comments