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

App.jsx

24 lines453 Bytes

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