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

client-component.tsx

24 lines463 Bytes

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