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