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

client-component.tsx

23 lines437 Bytes

1'use client'
2​
3import { useQuery } from '@tanstack/react-query'
4​
5export function ClientComponent() {
6 const query = useQuery({
7 queryKey: ['test'],
8 queryFn: async () => {
9 await new Promise((r) => setTimeout(r, 1000))
10 return 'Success'
11 },
12 })
13​
14 if (query.isPending) {
15 return <div>Loading...</div>
16 }
17​
18 if (query.isError) {
19 return <div>An error has occurred!</div>
20 }
21​
22 return <div>{query.data}</div>