Skip to content
Source
Sign inSign up
TanStack/router
Open History to see the last commit

posts-component.tsx

34 lines1.0 KB

1import * as React from 'react'
2import { Link, Outlet, useLoaderData, useMatch } from '@tanstack/react-router'
3import { routeConfig } from '../routes.generated/posts'
4import { postspostIdRoute } from '../routes.generated/posts/$postId.client'
5function Posts() {
6 const { posts } = useLoaderData({ from: routeConfig.id })
7 return (
8 <div className="p-2 flex gap-2">
9 <ul className="list-disc pl-4">
10 {posts?.map((post) => {
11 return (
12 <li key={post.id} className="whitespace-nowrap">
13 <Link
14 to={postspostIdRoute.id}
15 params={{
16 postId: post.id,
17 }}
18 className="block py-1 text-blue-800 hover:text-blue-600"
19 activeProps={{
20 className: 'text-black font-bold',
21 }}
22 >
23 <div>{post.title.substring(0, 20)}</div>
24 </Link>
25 </li>
26 )
27 })}
28 </ul>
29 <hr />
30 <Outlet />
31 </div>
32 )
34export const component = Posts