-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.tsx
51 lines (46 loc) · 1.38 KB
/
main.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import React, { StrictMode, useState } from 'react'
import { createRoot } from 'react-dom/client'
import {
createBrowserRouter,
RouterProvider,
useLoaderData,
useRouteError
} from "react-router-dom";
function App() {
const data = useLoaderData();
const [count, setCount] = useState(0)
return (
<>
<div>
</div>
<h1>Vite + React</h1>
<div className="card">
<button onClick={() => setCount((count) => count + 1)}>
count is {count}
</button>
<p>
{JSON.stringify(data)}
</p>
<p>
Edit <code>src/App.tsx</code> and save to test HMR
</p>
</div>
<p className="read-the-docs">
Click on the Vite and React logos to learn more
</p>
</>
)
}
createRoot(document.getElementById('root')!).render(
<StrictMode>
<RouterProvider router={createBrowserRouter([
// https://reactrouter.com/en/main/start/tutorial#nested-routes
{
path: "/",
element: <App />,
loader: async () => fetch("/api/hello"),
// errorElement: (() => <div>{JSON.stringify(useRouteError())}</div>)(),
},
])} />
</StrictMode>,
)