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