-
Notifications
You must be signed in to change notification settings - Fork 2
/
useDefaultToolbarItems.tsx
35 lines (33 loc) · 1.31 KB
/
useDefaultToolbarItems.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
/*---------------------------------------------------------------------------------------------
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
* See LICENSE.md in the project root for license terms and full copyright notice.
*--------------------------------------------------------------------------------------------*/
/** @packageDocumentation
* @module Toolbar
*/
import * as React from "react";
import type { ToolbarItem } from "./ToolbarItem";
import type { ToolbarItemsManager } from "./ToolbarItemsManager";
/** Hook that returns items from [[ToolbarItemsManager]].
* @public
* @deprecated in 4.4.0. Use [[Toolbar]] component instead of this hooks, ToolbarItemsManager is internal and should not be used here.
*/
export const useDefaultToolbarItems = (
// eslint-disable-next-line deprecation/deprecation
manager: ToolbarItemsManager
): readonly ToolbarItem[] => {
const [items, setItems] = React.useState(() => manager.items);
const isInitialMount = React.useRef(true);
React.useEffect(() => {
if (isInitialMount.current) isInitialMount.current = false;
else {
setItems(manager.items);
}
}, [manager, manager.items]);
React.useEffect(() => {
return manager.onItemsChanged.addListener((args) => {
setItems(args.items);
});
}, [manager]);
return items;
};