Open History to see the last commit
1'use client'
2β
3import { Temporal } from '@js-temporal/polyfill'
4import { useQuery } from '@tanstack/react-query'
5import React from 'react'
6β
7export function ClientComponent() {
8 const query = useQuery({
9 queryKey: ['data'],
10 queryFn: async () => {
11 const { count } = await (
12 await fetch('http://localhost:3000/count')
13 ).json()
14β
15 return {
16 text: 'data from client',
17 date: Temporal.PlainDate.from('2023-01-01'),
18 count,
19 }
20 },
21 })
22β
23 if (query.isPending) {
24 return <div>Loading...</div>
25 }
26β
27 if (query.isError) {
28 return <div>An error has occurred!</div>
29 }
30β
31 return (
32 <div>
33 {query.data.text} - {query.data.date.toJSON()} - {query.data.count}
34 </div>
35 )
36}