useIsFetching(...)
The Hook enables you to monitor the number of queries, matching the provided filters. This can be useful for creating loading indicators or performing other actions based on whether any requests are currently in progress. See the TanStack useIsFetching(...) ๐ด documentation for more details.
const queriesNumber = qraft.<service>.<operation>.useIsFetching(
filters,
queryClient,
)
Argumentsโ
filters?: QueryFiltersByParameters | QueryFiltersByQueryKey
- Optional, represents the Query Filters ๐ด to be used. If not provided, all normal and Infinite queries will be used to filter.
filters.parameters: { path, query, header }
will be used for filtering queries by parametersfilters.infinite: boolean
will be used to filter infinite or normal queriesfilters.queryKey: QueryKey
will be used for filtering queries by QueryKey instead of parametersfilters.queryKey
andfilters.parameters
are mutually exclusive
filters.predicate?: (query: Query) => boolean
will be used for filtering queries by custom predicate
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โ
number
: The number of queries that are matching the provided filters.
Exampleโ
src/FetchStatus.tsx
import { createAPIClient } from './api'; // generated by OpenAPI Qraft CLI
const qraft = createAPIClient();
function FetchStatus() {
// Checks all queries `GET /entities`
const fetchingTotal = qraft.entities.getEntities.useIsFetching();
// Checks all queries `GET /entities/3e3e-3e3e-3e3e` and `x-monite-version: 2023-09-01` header
const specificQueryKeyTotal = qraft.entities.getEntities.useIsFetching({
infinite: false,
parameters: {
header: {
'x-monite-version': '2023-09-01',
},
path: {
entity_id: '3e3e-3e3e-3e3e',
},
},
});
return (
<>
{!!fetchingTotal && <div>Number of queries: {fetchingTotal}...</div>}
{!!specificQueryKeyTotal && <div>Loading specific query...</div>}
</>
);
}