Open History to see the last commit
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 { QueryClient, QueryClientProvider, useQuery } from '@tanstack/react-query'
11β
12const queryClient = new QueryClient()
13β
14function Example() {
15 const query = useQuery({ queryKey: ['todos'], queryFn: fetchTodos })
16β
17 return (
18 <div>
19 {query.isPending
20 ? 'Loading...'
21 : query.isError
22 ? 'Error!'
23 : query.data
24 ? query.data.map((todo) => <div key={todo.id}>{todo.title}</div>)
25 : null}
26 </div>
27 )
28}
29β
30function App () {
31 return (
32 <QueryClientProvider client={queryClient}>
33 <Example />
34 </QueryClientProvider>
35 )
36}
37```