main.tsx 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. import {useState} from 'react';
  2. import {createBrowserRouter, RouterProvider} from 'react-router-dom';
  3. import {wrapCreateBrowserRouter} from '@sentry/react';
  4. import {ReactQueryDevtools} from '@tanstack/react-query-devtools';
  5. import DemoHeader from 'sentry/components/demo/demoHeader';
  6. import {OnboardingContextProvider} from 'sentry/components/onboarding/onboardingContext';
  7. import {ThemeAndStyleProvider} from 'sentry/components/themeAndStyleProvider';
  8. import {USE_REACT_QUERY_DEVTOOL} from 'sentry/constants';
  9. import {routes} from 'sentry/routes';
  10. import ConfigStore from 'sentry/stores/configStore';
  11. import {DANGEROUS_SET_REACT_ROUTER_6_HISTORY} from 'sentry/utils/browserHistory';
  12. import {
  13. DEFAULT_QUERY_CLIENT_CONFIG,
  14. QueryClient,
  15. QueryClientProvider,
  16. } from 'sentry/utils/queryClient';
  17. import {buildReactRouter6Routes} from './utils/reactRouter6Compat/router';
  18. const queryClient = new QueryClient(DEFAULT_QUERY_CLIENT_CONFIG);
  19. function buildRouter() {
  20. const sentryCreateBrowserRouter = wrapCreateBrowserRouter(createBrowserRouter);
  21. const router = sentryCreateBrowserRouter(buildReactRouter6Routes(routes()));
  22. DANGEROUS_SET_REACT_ROUTER_6_HISTORY(router);
  23. return router;
  24. }
  25. function Main() {
  26. const [router] = useState(buildRouter);
  27. return (
  28. <ThemeAndStyleProvider>
  29. <QueryClientProvider client={queryClient}>
  30. <OnboardingContextProvider>
  31. {ConfigStore.get('demoMode') && <DemoHeader />}
  32. <RouterProvider router={router} />
  33. </OnboardingContextProvider>
  34. {USE_REACT_QUERY_DEVTOOL && (
  35. <ReactQueryDevtools initialIsOpen={false} buttonPosition="bottom-left" />
  36. )}
  37. </QueryClientProvider>
  38. </ThemeAndStyleProvider>
  39. );
  40. }
  41. export default Main;