mirror of
https://github.com/hanzoai/sentinel.git
synced 2026-09-29 22:34:33 +00:00
31 lines
856 B
TypeScript
31 lines
856 B
TypeScript
import {useEffect, useMemo, useState} from 'react';
|
|
|
|
import SentryAppComponentsStore from 'sentry/stores/sentryAppComponentsStore';
|
|
import type {SentryAppComponent} from 'sentry/types';
|
|
|
|
export default function useSentryAppComponentsStore({
|
|
componentType,
|
|
}: {
|
|
componentType: undefined | SentryAppComponent['type'];
|
|
}) {
|
|
const [components, setComponents] = useState(SentryAppComponentsStore.getAll());
|
|
|
|
useEffect(() => {
|
|
const unsubscribe = SentryAppComponentsStore.listen(
|
|
() => setComponents(SentryAppComponentsStore.getAll()),
|
|
undefined
|
|
);
|
|
|
|
return unsubscribe as () => void;
|
|
}, []);
|
|
|
|
const filteredComponents = useMemo(() => {
|
|
if (componentType) {
|
|
return components.filter(item => item.type === componentType);
|
|
}
|
|
return components;
|
|
}, [components, componentType]);
|
|
|
|
return filteredComponents;
|
|
}
|