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