useQueries(...)
The Hook enables you to concurrently execute multiple asynchronous data fetching operations. For more detailed information, explore the TanStack useQueries(...) ๐ด documentation.
const queries = api.<service>.<operation>.useQueries(
options
)
Argumentsโ
options: UseQueriesOptions
- Required, represents the options for queries, see useQueries(...) ๐ด documentation
options.queries: QueryOptions[]
- Required array of Queries to be executed
parameters: { path, query, header }
will be used for the requestqueryKey: QueryKey
will be used for the request instead of theparameters
queryKey
andparameters
are mutually exclusive
options.combine?: (result: UseQueriesResults) => TCombinedResult
- Optional, a function to select the data from the mutation
Returnsโ
Array with all the Queries
. The order returned is the same as the input order.
tip
By default, useQueries
hooks are only generated for read operations (GET method). If you want to use query
hooks for write operations (POST, PUT, PATCH methods), use the --queryable-write-operations
CLI option
during code generation.
Exampleโ
import { createAPIClient } from './api'; // generated by OpenAPI Qraft
import { requestFn } from '@openapi-qraft/react';
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
const queryClient = new QueryClient();
const api = createAPIClient({
requestFn,
queryClient,
baseUrl: 'https://api.sandbox.monite.com/v1',
});
const useEntityQueries = () => {
/**
* Initiates two concurrent GET requests:
* ###
* GET /entities/3e3e-3e3e-3e3e
* x-monite-version: 2023-09-01
* ###
* GET /entities/5c5c-5c5c-5c5c
* x-monite-version: 2023-09-01
**/
return api.entities.getEntities.useQueries({
queries: [
{
parameters: {
header: {
'x-monite-version': '2023-09-01',
},
path: {
entity_id: '3e3e-3e3e-3e3e',
},
},
},
{
parameters: {
header: {
'x-monite-version': '2023-09-01',
},
path: {
entity_id: '5c5c-5c5c-5c5c',
},
},
},
],
combine: (results) => results.map((result) => result.data),
});
}