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

useQueries.md

28 lines1.1 KB

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](../../../../framework/react/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> Having the same query key more than once in the array of query objects may cause some data to be shared between queries, e.g. when using `placeholderData` and `select`. To avoid this, consider de-duplicating the queries and map the results back to the desired structure.
25​
26**Returns**
27​
28The `useQueries` hook returns an array with all the query results. The order returned is the same as the input order.