Open History to see the last commit
1import { useQuery } from '@tanstack/solid-query'
2import { Link, Outlet, createFileRoute } from '@tanstack/solid-router'
3import { For, Suspense } from 'solid-js'
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 = useQuery(() => postsQueryOptions())
16β
17 return (
18 <div class="p-2 flex gap-2">
19 <ul class="list-disc pl-4">
20 <Suspense fallback={<div>Loading posts...</div>}>
21 <For
22 each={[
23 ...(postsQuery.data || []),
24 { id: 'i-do-not-exist', title: 'Non-existent Post' },
25 ]}
26 >
27 {(post) => (
28 <li class="whitespace-nowrap">
29 <Link
30 to="/posts/$postId"
31 params={{
32 postId: post.id,
33 }}
34 class="block py-1 text-blue-800 hover:text-blue-600"
35 activeProps={{ class: 'text-black font-bold' }}
36 >
37 <div>{post.title.substring(0, 20)}</div>
38 </Link>
39 </li>
40 )}
41 </For>
42 </Suspense>
43 </ul>
44 <hr />
45 <Outlet />
46 </div>
47 )
48}