diff --git a/docs/data/tree-view/rich-tree-view/items/items.md b/docs/data/tree-view/rich-tree-view/items/items.md index 322e8c3dba80..fbf179e3685e 100644 --- a/docs/data/tree-view/rich-tree-view/items/items.md +++ b/docs/data/tree-view/rich-tree-view/items/items.md @@ -151,6 +151,19 @@ Use the `onItemClick` prop to track the clicked item: ## Imperative API +:::success +To use the `apiRef` object, you need to initialize it using the `useTreeViewApiRef` hook as follows: + +```tsx +const apiRef = useTreeViewApiRef(); + +return ; +``` + +When your component first renders, `apiRef` will be `undefined`. +After this initial render, `apiRef` holds methods to interact imperatively with the Tree View. +::: + ### Get an item by ID Use the `getItem` API method to get an item by its ID. diff --git a/docs/data/tree-view/rich-tree-view/selection/selection.md b/docs/data/tree-view/rich-tree-view/selection/selection.md index 2c45bd280411..2175d7ad3978 100644 --- a/docs/data/tree-view/rich-tree-view/selection/selection.md +++ b/docs/data/tree-view/rich-tree-view/selection/selection.md @@ -103,7 +103,7 @@ To use the `apiRef` object, you need to initialize it using the `useTreeViewApiR ```tsx const apiRef = useTreeViewApiRef(); -return {children}; +return ; ``` When your component first renders, `apiRef` will be `undefined`. diff --git a/docs/data/tree-view/simple-tree-view/items/items.md b/docs/data/tree-view/simple-tree-view/items/items.md index 755b162c915d..c177b4769e2f 100644 --- a/docs/data/tree-view/simple-tree-view/items/items.md +++ b/docs/data/tree-view/simple-tree-view/items/items.md @@ -82,6 +82,19 @@ Use the `onItemClick` prop to track the clicked item: ## Imperative API +:::success +To use the `apiRef` object, you need to initialize it using the `useTreeViewApiRef` hook as follows: + +```tsx +const apiRef = useTreeViewApiRef(); + +return {children}; +``` + +When your component first renders, `apiRef` will be `undefined`. +After this initial render, `apiRef` holds methods to interact imperatively with the Tree View. +::: + ### Get an item's DOM element by ID Use the `getItemDOMElement` API method to get an item's DOM element by its ID.