forked from TanStack/router
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathposts.lazy.tsx
40 lines (36 loc) · 1.15 KB
/
posts.lazy.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
import * as React from 'react'
import { Link, Outlet, createLazyRoute } from '@tanstack/react-router'
import { useSuspenseQuery } from '@tanstack/react-query'
import { postsQueryOptions } from './posts'
export const Route = createLazyRoute('/posts')({
component: PostsComponent,
})
function PostsComponent() {
const postsQuery = useSuspenseQuery(postsQueryOptions)
const posts = postsQuery.data
return (
<div className="p-2 flex gap-2">
<ul className="list-disc pl-4">
{[...posts, { id: 'i-do-not-exist', title: 'Non-existent Post' }].map(
(post) => {
return (
<li key={post.id} className="whitespace-nowrap">
<Link
to="/posts/$postId"
params={{
postId: post.id,
}}
className="block py-1 px-2 text-blue-600 hover:opacity-75"
activeProps={{ className: 'font-bold underline' }}
>
<div>{post.title.substring(0, 20)}</div>
</Link>
</li>
)
},
)}
</ul>
<Outlet />
</div>
)
}