Open History to see the last commit
1import { useSuspenseQuery } from '@tanstack/react-query'
2import { Link, Outlet, createFileRoute } from '@tanstack/react-router'
3β
4import { postsQueryOptions } from '~/utils/posts'
5β
6export const Route = createFileRoute('/posts')({
7 loader: async ({ context }) => {
8 await context.queryClient.ensureQueryData(postsQueryOptions())
9 },
10 head: () => ({ meta: [{ title: 'Posts' }] }),
11 component: PostsComponent,
12})
13β
14function PostsComponent() {
15 const postsQuery = useSuspenseQuery(postsQueryOptions())
16β
17 return (
18 <div className="p-2 flex gap-2">
19 <ul className="list-disc pl-4">
20 {[
21 ...postsQuery.data,
22 { id: 'i-do-not-exist', title: 'Non-existent Post' },
23 ].map((post) => {
24 return (
25 <li key={post.id} className="whitespace-nowrap">
26 <Link
27 to="/posts/$postId"
28 params={{
29 postId: post.id,
30 }}
31 className="block py-1 text-blue-800 hover:text-blue-600"
32 activeProps={{ className: 'text-black font-bold' }}
33 >
34 <div>{post.title.substring(0, 20)}</div>
35 </Link>
36 </li>
37 )
38 })}
39 </ul>
40 <hr />
41 <Outlet />
42 </div>
43 )
44}