-
Notifications
You must be signed in to change notification settings - Fork 2
/
useDefaultStatusBarItems.tsx
33 lines (31 loc) · 1.13 KB
/
useDefaultStatusBarItems.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
/*---------------------------------------------------------------------------------------------
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
* See LICENSE.md in the project root for license terms and full copyright notice.
*--------------------------------------------------------------------------------------------*/
/** @packageDocumentation
* @module StatusBar
*/
import * as React from "react";
import type { StatusBarItem } from "./StatusBarItem";
import type { StatusBarItemsManager } from "./StatusBarItemsManager";
/** Hook that returns items from [[StatusBarItemsManager]].
* @public
*/
export const useDefaultStatusBarItems = (
manager: StatusBarItemsManager
): readonly StatusBarItem[] => {
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]);
React.useEffect(() => {
return manager.onItemsChanged.addListener((args) => {
setItems(args.items);
});
}, [manager]);
return items;
};