Open History to see the last commit
1import { Temporal } from '@js-temporal/polyfill'
2import { HydrationBoundary, dehydrate, noop } from '@tanstack/react-query'
3import { headers } from 'next/headers'
4import React from 'react'
5import { queryExampleAction } from './_action'
6import { ClientComponent } from './client-component'
7import { makeQueryClient } from './make-query-client'
8β
9export default function Home() {
10 const queryClient = makeQueryClient()
11β
12 queryClient
13 .query({
14 queryKey: ['data'],
15 queryFn: async () => {
16 const { count } = await (
17 await fetch('http://localhost:3000/count', {
18 headers: await headers(),
19 })
20 ).json()
21β
22 return {
23 text: 'data from server',
24 date: Temporal.PlainDate.from('2024-01-01'),
25 count,
26 }
27 },
28 })
29 .catch(noop)
30β
31 const state = dehydrate(queryClient)
32β
33 return (
34 <main>
35 <HydrationBoundary state={state}>
36 <ClientComponent />
37 </HydrationBoundary>
38 <form action={queryExampleAction}>
39 <button type="submit">Increment</button>
40 </form>
41 </main>
42 )
43}