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

dashboard.index.tsx

26 lines705 Bytes

1import { createFileRoute } from '@tanstack/react-router'
2import { useQuery } from '@tanstack/react-query'
3import { trpc } from '../router'
4​
5export const Route = createFileRoute('/dashboard/')({
6 loader: async ({ context: { trpc, queryClient } }) => {
7 await queryClient.ensureQueryData(trpc.posts.queryOptions())
8 return
9 },
10 component: DashboardIndexComponent,
11})
12​
13function DashboardIndexComponent() {
14 const postsQuery = useQuery(trpc.posts.queryOptions())
15​
16 const posts = postsQuery.data || []
17​
18 return (
19 <div className="p-2">
20 <div className="p-2">
21 Welcome to the dashboard! You have{' '}
22 <strong>{posts.length} total posts</strong>.
23 </div>
24 </div>
25 )