useSuspenseQuery(...)
See the useSuspenseQuery(...) ๐ด documentation.
The Hook enables you to perform asynchronous data fetching operations, similar to useQuery Hook, but with the added benefit of Suspense support. See the TanStack useSuspenseQuery(...) ๐ด documentation for more details.
const result = qraft.<service>.<operation>.useSuspenseQuery(
parameters,
queryOptions,
queryClient,
)
Argumentsโ
-
parameters: { path, query, header } | QueryKey | {}- Required, OpenAPI request parameters for the query, strictly-typed โจ
parameterswill be used to generate theQueryKey- Instead of an object with
{path, query, header}, you can pass aQueryKeyas an array which is also strictly-typed โจ - If operation does not require parameters, you must pass an empty object
{}for strictness
-
queryOptions?: UseQueryOptions- Optional, represents the options of the useSuspenseQuery(...) ๐ด Hook
queryOptions.queryFncould be provided to override the defaultqueryFnused by Qraftis not allowed, as it will be generated fromqueryOptions.queryKeyparameters
- Optional, represents the options of the useSuspenseQuery(...) ๐ด Hook
-
queryClient?: QueryClient- Optional QueryClient ๐ด to be used
- If not provided
QraftContext.queryClientwill be used if available- useQueryClient() ๐ด result will be used as a fallback
Returnsโ
TData - the result from the query
Exampleโ
src/ApprovalPolicyName.tsx
import { Suspense } from 'react';
import { createAPIClient } from './api'; // generated by OpenAPI Qraft CLI
const qraft = createAPIClient();
function ApprovalPolicyName() {
/**
* `<service>.<operation>.useSuspenseQuery(...)` initiates
* the request for data retrieval:
* ###
* GET /approval_policies/321?items_order=asc&items_order=desc
* x-monite-version: 1.0.0
*/
const approvalPolicy =
qraft.approvalPolicies.getApprovalPoliciesId.useSuspenseQuery(
{
header: {
"x-monite-version": "1.0.0",
},
path: {
approval_policy_id: "123",
},
query: {
items_order: ["asc", "desc"],
},
},
);
return <div>Approval Policy: {approvalPolicy.name}</div>;
}
export default function() {
return (
<Suspense fallback={<div>Loading...</div>}>
<ApprovalPolicyName />
</Suspense>
);
}