Open History to see the last commit
1import * as React from 'react'
2import * as ReactDOM from 'react-dom/client'
3import { createBrowserRouter } from 'react-router'
4import { RouterProvider } from 'react-router/dom'
5import { QueryClient, QueryClientProvider } from '@tanstack/react-query'
6import { ReactQueryDevtools } from '@tanstack/react-query-devtools'
7β
8import './index.css'
9β
10import ErrorPage from './error-page'
11import Root, { loader as rootLoader } from './routes/root'
12import Contact, {
13 action as contactAction,
14 loader as contactLoader,
15} from './routes/contact'
16import EditContact, { action as editAction } from './routes/edit'
17import { action as destroyAction } from './routes/destroy'
18import Index from './routes/index'
19import NewContact, { action as newAction } from './routes/new'
20β
21const queryClient = new QueryClient({
22 defaultOptions: {
23 queries: {
24 staleTime: 10 * 1000,
25 },
26 },
27})
28β
29const router = createBrowserRouter([
30 {
31 path: '/',
32 element: <Root />,
33 errorElement: <ErrorPage />,
34 loader: rootLoader(queryClient),
35 children: [
36 {
37 index: true,
38 element: <Index />,
39 },
40 {
41 path: 'contacts/new',
42 element: <NewContact />,
43 action: newAction(queryClient),
44 errorElement: <ErrorPage />,
45 },
46 {
47 path: 'contacts/:contactId',
48 element: <Contact />,
49 loader: contactLoader(queryClient),
50 action: contactAction(queryClient),
51 errorElement: <ErrorPage />,
52 },
53 {
54 path: 'contacts/:contactId/edit',
55 element: <EditContact />,
56 loader: contactLoader(queryClient),
57 action: editAction(queryClient),
58 errorElement: <ErrorPage />,
59 },
60 {
61 path: 'contacts/:contactId/destroy',
62 element: <EditContact />,
63 action: destroyAction(queryClient),
64 errorElement: <ErrorPage />,
65 },
66 ],
67 },
68])
69β
70const rootElement = document.getElementById('root')
71if (!rootElement) throw new Error('Missing #root element')
72ReactDOM.createRoot(rootElement).render(
73 <React.StrictMode>
74 <QueryClientProvider client={queryClient}>
75 <RouterProvider router={router} />
76 <ReactQueryDevtools buttonPosition="bottom-right" />
77 </QueryClientProvider>
78 </React.StrictMode>,
79)