Skip to main content
Version: 1.x

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โ€‹

  1. 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 parameters
    • filters.infinite: boolean will be used to filter infinite or normal queries
    • filters.queryKey: QueryKey will be used for filtering queries by QueryKey instead of parameters
      • filters.queryKey and filters.parameters are mutually exclusive
    • filters.predicate?: (query: Query) => boolean will be used for filtering queries by custom predicate
  2. queryClient?: QueryClient

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>}
</>
);
}