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