Open History to see the last commit
1import { useQuery } from '@tanstack/solid-query'
2import { ErrorComponent, Link, createFileRoute } from '@tanstack/solid-router'
3import { postQueryOptions } from '~/utils/posts'
4β
5export function PostErrorComponent({ error }: { error: any }) {
6 return <ErrorComponent error={error} />
7}
8β
9export const Route = createFileRoute('/posts/$postId')({
10 loader: async ({ context, params }) => {
11 await context.queryClient.ensureQueryData(postQueryOptions(params.postId))
12 },
13 errorComponent: PostErrorComponent,
14 component: PostComponent,
15})
16β
17function PostComponent() {
18 const params = Route.useParams()
19 const postQuery = useQuery(() => postQueryOptions(params().postId))
20β
21 return (
22 <div class="space-y-2">
23 <h4 class="text-xl font-bold underline">{postQuery.data?.title}</h4>
24 <div class="text-sm">{postQuery.data?.body}</div>
25 <Link
26 to="/posts/$postId/deep"
27 params={{
28 postId: postQuery.data?.id ?? '',
29 }}
30 activeProps={{ class: 'text-black font-bold' }}
31 class="inline-block py-1 text-blue-800 hover:text-blue-600"
32 >
33 Deep View
34 </Link>
35 </div>
36 )
37}