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