-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Expand file tree
/
Copy pathusers.tsx
More file actions
50 lines (44 loc) · 1.26 KB
/
users.tsx
File metadata and controls
50 lines (44 loc) · 1.26 KB
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
import { Link, Outlet, createFileRoute } from '@tanstack/react-router'
import { DEPLOY_URL } from '../utils/users'
import type { User } from '../utils/users'
export const Route = createFileRoute('/users')({
loader: async () => {
const res = await fetch(DEPLOY_URL + '/api/users')
if (!res.ok) {
throw new Error('Unexpected status code')
}
const data = await res.json()
return data as Array<User>
},
component: UsersComponent,
})
function UsersComponent() {
const users = Route.useLoaderData()
return (
<div className="p-2 flex gap-2">
<ul className="list-disc pl-4">
{[
...users,
{ id: 'i-do-not-exist', name: 'Non-existent User', email: '' },
].map((user) => {
return (
<li key={user.id} className="whitespace-nowrap">
<Link
to="/users/$userId"
params={{
userId: String(user.id),
}}
className="block py-1 text-blue-800 hover:text-blue-600"
activeProps={{ className: 'text-black font-bold' }}
>
<div>{user.name}</div>
</Link>
</li>
)
})}
</ul>
<hr />
<Outlet />
</div>
)
}