Skip to content

Commit

Permalink
[docs] Add missing callout on Imperative API tree view sections
Browse files Browse the repository at this point in the history
  • Loading branch information
flaviendelangle committed Sep 5, 2024
1 parent 2ccdaa3 commit 7a4c6d7
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 1 deletion.
13 changes: 13 additions & 0 deletions docs/data/tree-view/rich-tree-view/items/items.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 <RichTreeView apiRef={apiRef} items={ITEMS}>;
```

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.
Expand Down
2 changes: 1 addition & 1 deletion docs/data/tree-view/rich-tree-view/selection/selection.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ To use the `apiRef` object, you need to initialize it using the `useTreeViewApiR
```tsx
const apiRef = useTreeViewApiRef();

return <SimpleTreeView apiRef={apiRef}>{children}</SimpleTreeView>;
return <RichTreeView apiRef={apiRef} items={ITEMS}>;
```

When your component first renders, `apiRef` will be `undefined`.
Expand Down
13 changes: 13 additions & 0 deletions docs/data/tree-view/simple-tree-view/items/items.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 <SimpleTreeView apiRef={apiRef}>{children}</SimpleTreeView>;
```

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.
Expand Down

0 comments on commit 7a4c6d7

Please sign in to comment.