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

react-query.md

41 lines932 Bytes

1---
2title: React Query
3---
4​
5The `react-query` package offers a 1st-class API for using TanStack Query via React. However, all of the primitives you receive from these hooks are core APIs that are shared across all of the TanStack Adapters including the Query Client, query results, query subscriptions, etc.
6​
7## Example
8​
9```tsx
10import {
11 QueryClient,
12 QueryClientProvider,
13 useQuery,
14} from '@tanstack/react-query'
15​
16const queryClient = new QueryClient()
17​
18function Example() {
19 const query = useQuery({ queryKey: ['todos'], queryFn: fetchTodos })
20​
21 return (
22 <div>
23 {query.isPending
24 ? 'Loading...'
25 : query.isError
26 ? 'Error!'
27 : query.data
28 ? query.data.map((todo) => <div key={todo.id}>{todo.title}</div>)
29 : null}
30 </div>
31 )
33​
34function App() {
35 return (
36 <QueryClientProvider client={queryClient}>
37 <Example />
38 </QueryClientProvider>
39 )
41```