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

page.tsx

29 lines926 Bytes

1import React from 'react'
2import { HydrationBoundary, dehydrate, noop } 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
11 .query({
12 queryKey: ['todos'],
13 queryFn: getTodos,
14 })
15 .catch(noop)
16​
17 return (
18 <main style={{ maxWidth: 600, margin: '0 auto', padding: '2rem 1rem' }}>
19 <h1>Optimistic Updates with TanStack Query</h1>
20 <p style={{ color: '#666', marginBottom: '1.5rem' }}>
21 Add todos to see optimistic updates in action. The server randomly fails
22 ~30% of the time so you can observe automatic rollback.
23 </p>
24 <HydrationBoundary state={dehydrate(queryClient)}>
25 <ApproachTabs />
26 </HydrationBoundary>
27 </main>
28 )