dashboardsMEPContext.tsx 957 B

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