dashboardsMEPContext.tsx 984 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. import type {ReactNode} from 'react';
  2. import {useState} from 'react';
  3. import {createDefinedContext} from 'sentry/utils/performance/contexts/utils';
  4. interface DashboardsMEPContextInterface {
  5. setIsMetricsData: (value?: boolean) => void;
  6. isMetricsData?: boolean;
  7. }
  8. const [_DashboardsMEPProvider, useDashboardsMEPContext, DashboardsMEPContext] =
  9. createDefinedContext<DashboardsMEPContextInterface>({
  10. name: 'DashboardsMEPContext',
  11. });
  12. const DashboardsMEPConsumer = DashboardsMEPContext.Consumer;
  13. function DashboardsMEPProvider({children}: {children: ReactNode}) {
  14. const [isMetricsData, setIsMetricsData] = useState<boolean | undefined>(undefined); // undefined means not initialized
  15. return (
  16. <_DashboardsMEPProvider
  17. value={{
  18. isMetricsData,
  19. setIsMetricsData,
  20. }}
  21. >
  22. {children}
  23. </_DashboardsMEPProvider>
  24. );
  25. }
  26. export {
  27. DashboardsMEPContext,
  28. DashboardsMEPProvider,
  29. DashboardsMEPConsumer,
  30. useDashboardsMEPContext,
  31. };