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 {
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 )
32}
33β
34function App() {
35 return (
36 <QueryClientProvider client={queryClient}>
37 <Example />
38 </QueryClientProvider>
39 )
40}
41```