main.tsx 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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 {DANGEROUS_SET_REACT_ROUTER_6_HISTORY} from 'sentry/utils/browserHistory';
  11. import {
  12. DEFAULT_QUERY_CLIENT_CONFIG,
  13. QueryClient,
  14. QueryClientProvider,
  15. } from 'sentry/utils/queryClient';
  16. import {buildReactRouter6Routes} from './utils/reactRouter6Compat/router';
  17. const queryClient = new QueryClient(DEFAULT_QUERY_CLIENT_CONFIG);
  18. function buildRouter() {
  19. const sentryCreateBrowserRouter = wrapCreateBrowserRouter(createBrowserRouter);
  20. const router = sentryCreateBrowserRouter(buildReactRouter6Routes(routes()));
  21. DANGEROUS_SET_REACT_ROUTER_6_HISTORY(router);
  22. return router;
  23. }
  24. function Main() {
  25. const [router] = useState(buildRouter);
  26. return (
  27. <ThemeAndStyleProvider>
  28. <QueryClientProvider client={queryClient}>
  29. <OnboardingContextProvider>
  30. <DemoHeader />
  31. <RouterProvider router={router} />
  32. </OnboardingContextProvider>
  33. {USE_REACT_QUERY_DEVTOOL && (
  34. <ReactQueryDevtools initialIsOpen={false} buttonPosition="bottom-left" />
  35. )}
  36. </QueryClientProvider>
  37. </ThemeAndStyleProvider>
  38. );
  39. }
  40. export default Main;