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