useSuspenseQueries(...)
See the useSuspenseQueries(...) ๐ด documentation.
The Hook enables you to concurrently execute multiple asynchronous data fetching operations. The functionality is similar to the useQueries hook, but with the added benefit of Suspense support. For more detailed information, explore the TanStack useSuspenseQueries(...) ๐ด documentation.
const result = qraft.<service>.<operation>.useSuspenseQueries(
options,
queryClient
)
Argumentsโ
options: UseQueriesOptions
- Required, represents the options for queries, see useSuspenseQueries(...) ๐ด 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
queryClient?: QueryClient
- Optional QueryClient ๐ด to be used
- If not provided
QraftContext.queryClient
will be used if available- useQueryClient() ๐ด result will be used as a fallback
Returnsโ
Array with all the query results. The order returned is the same as the input order.
Exampleโ
src/Entities.tsx
import { Suspense } from 'react'
import { createAPIClient } from './api'; // generated by OpenAPI Qraft
const qraft = createAPIClient();
function Entities() {
/**
* Initiates two GET requests for entity details:
* ###
* GET /entities/3e3e-3e3e-3e3e
* x-monite-version: 2023-09-01
* ###
* GET /entities/5c5c-5c5c-5c5c
* x-monite-version: 2023-09-01
**/
const entities = qraft.entities.getEntities.useSuspenseQueries({
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),
});
return (
<p>
{entities.map(({id}) => id).join(', ')}
</p>
)
}
export default function() {
return (
<Suspense fallback={<div>Loading...</div>}>
<Entities />
</Suspense>
)
}