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

react-query.md

37 lines914 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 { 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 )
29​
30function App () {
31 return (
32 <QueryClientProvider client={queryClient}>
33 <Example />
34 </QueryClientProvider>
35 )
37```