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

client-component.tsx

32 lines655 Bytes

1'use client'
2​
3import React from 'react'
4import { useQuery } from '@tanstack/react-query'
5import { Temporal } from '@js-temporal/polyfill'
6​
7export function ClientComponent() {
8 const query = useQuery({
9 queryKey: ['data'],
10 queryFn: async () => {
11 await new Promise((r) => setTimeout(r, 1000))
12 return {
13 text: 'data from client',
14 date: Temporal.PlainDate.from('2023-01-01'),
15 }
16 },
17 })
18​
19 if (query.isPending) {
20 return <div>Loading...</div>
21 }
22​
23 if (query.isError) {
24 return <div>An error has occurred!</div>
25 }
26​
27 return (
28 <div>
29 {query.data.text} - {query.data.date.toJSON()}
30 </div>
31 )