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