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

page.tsx

27 lines900 Bytes

1import React from 'react'
2import { HydrationBoundary, dehydrate } from '@tanstack/react-query'
3import { getQueryClient } from '@/app/get-query-client'
4import { getTodos } from '@/app/api/todos/data'
5import ApproachTabs from '@/components/ApproachTabs'
6​
7export default function Home() {
8 const queryClient = getQueryClient()
9​
10 void queryClient.prefetchQuery({
11 queryKey: ['todos'],
12 queryFn: getTodos,
13 })
14​
15 return (
16 <main style={{ maxWidth: 600, margin: '0 auto', padding: '2rem 1rem' }}>
17 <h1>Optimistic Updates with TanStack Query</h1>
18 <p style={{ color: '#666', marginBottom: '1.5rem' }}>
19 Add todos to see optimistic updates in action. The server randomly fails
20 ~30% of the time so you can observe automatic rollback.
21 </p>
22 <HydrationBoundary state={dehydrate(queryClient)}>
23 <ApproachTabs />
24 </HydrationBoundary>
25 </main>
26 )