main
js 38 lines 1.14 KB
Raw
1 /**
2 * Copyright (c) Meta Platforms, Inc. and affiliates.
3 *
4 * This source code is licensed under the MIT license found in the
5 * LICENSE file in the root directory of this source tree.
6 *
7 * @flow
8 */
9
10 import {useState, useEffect} from 'react';
11 import type {FrontendBridge} from 'react-devtools-shared/src/bridge';
12
13 // Events that are prefixed with `extension` will only be emitted for the browser extension implementation.
14 // For other implementations, this hook will just return constant `true` value.
15 export function useExtensionComponentsPanelVisibility(
16 bridge: FrontendBridge,
17 ): boolean {
18 const [isVisible, setIsVisible] = useState(true);
19
20 useEffect(() => {
21 function onPanelShown() {
22 setIsVisible(true);
23 }
24 function onPanelHidden() {
25 setIsVisible(false);
26 }
27
28 bridge.addListener('extensionComponentsPanelShown', onPanelShown);
29 bridge.addListener('extensionComponentsPanelHidden', onPanelHidden);
30
31 return () => {
32 bridge.removeListener('extensionComponentsPanelShown', onPanelShown);
33 bridge.removeListener('extensionComponentsPanelHidden', onPanelHidden);
34 };
35 }, [bridge]);
36
37 return isVisible;
38 }