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, action as rootAction } 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'
18β
19const queryClient = new QueryClient({
20 defaultOptions: {
21 queries: {
22 staleTime: 1000 * 10,
23 },
24 },
25})
26β
27const router = createBrowserRouter([
28 {
29 path: '/',
30 element: <Root />,
31 errorElement: <ErrorPage />,
32 loader: rootLoader(queryClient),
33 action: rootAction(queryClient),
34 children: [
35 {
36 index: true,
37 element: <Index />,
38 },
39 {
40 path: 'contacts/:contactId',
41 element: <Contact />,
42 loader: contactLoader(queryClient),
43 action: contactAction(queryClient),
44 },
45 {
46 path: 'contacts/:contactId/edit',
47 element: <EditContact />,
48 loader: contactLoader(queryClient),
49 action: editAction(queryClient),
50 },
51 {
52 path: 'contacts/:contactId/destroy',
53 element: <EditContact />,
54 action: destroyAction(queryClient),
55 errorElement: <div>Oops! There was an error.</div>,
56 },
57 ],
58 },
59])
60β
61const rootElement = document.getElementById('root')
62ReactDOM.createRoot(rootElement).render(
63 <React.StrictMode>
64 <QueryClientProvider client={queryClient}>
65 <RouterProvider router={router} />
66 <ReactQueryDevtools position="bottom-right" />
67 </QueryClientProvider>
68 </React.StrictMode>,
69)