Skip to main content

Prop Memoization

Feature making all props created by HT consistent and useable for memoization

SourceView Source
TypesView Types
Importimport { prop-memoizationFeature } from "@headless-tree/core
Type DocumentationConfigurationStateTree InstanceItem Instance

By default, React props generated by tree.getContainerProps() and item.getProps() will not be memoized, and might change their reference during each render as they are generated fresh each time.

If you rely on stable props, or need them to be memoized, you can simply include the propMemoizationFeature and the props will be memoized automatically. The feature doesn't require any configuration or expose any methods.

Example

Consider this sample, where the render method of each item is intentionally slowed down, resulting in a slow usage experience when expanding or collapsing items:

Here, the render method is memoized and the propMemoizationFeature is included. Tree items still render slowly during the initial render, but items that are unchanged during rerender do not retrigger the slow render function, resulting in a faster experience when expanding or collapsing items: