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

useQueries.md

26 lines771 Bytes

1---
2id: useQueries
3title: useQueries
4---
5​
6The `useQueries` hook can be used to fetch a variable number of queries:
7​
8```tsx
9const results = useQueries({
10 queries: [
11 { queryKey: ['post', 1], queryFn: fetchPost, staleTime: Infinity},
12 { queryKey: ['post', 2], queryFn: fetchPost, staleTime: Infinity}
13 ]
14})
15```
16​
17**Options**
18​
19The `useQueries` hook accepts an options object with a **queries** key whose value is an array with query option objects identical to the [`useQuery` hook](../reference/useQuery) (excluding the `context` option).
20​
21- `context?: React.Context<QueryClient | undefined>`
22 - Use this to use a custom React Query context. Otherwise, `defaultContext` will be used.
23​
24**Returns**
25​
26The `useQueries` hook returns an array with all the query results.