useIsMutating(...)
The optional hook that returns the number
of mutations that your
application is mutating (useful for app-wide loading indicators).
See the TanStack useIsMutating(...) ๐ด
documentation for more details.
const mutationNumber = qraft.<service>.<operation>.useIsMutating(
filters,
queryClient,
)
Argumentsโ
filters?: UseMutationStateFiltersByParameters | UseMutationStateFiltersByMutationKey
,- Optional, represents the Mutation Filters ๐ด to be used, strictly-typed โจ
filters.parameters: { path, query, header }
will be used for filtering mutations by parametersfilters.mutationKey: MutationKey
will be used for filtering mutations by MutationKey instead of parametersfilters.mutationKey
andfilters.parameters
are mutually exclusive
filters.predicate?: (mutation: Mutation) => boolean
will be used for filtering mutations by custom predicate- If not provided, all mutations matching to
<service>.<operation>
will be returned
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โ
mutationsNumber
: The number of mutations that are matching the provided filters and are in the loading state
Exampleโ
src/DocumentsUploadStatus.tsx
import { createAPIClient } from './api'; // generated by OpenAPI Qraft CLI
const qraft = createAPIClient();
function DocumentsUploadStatus() {
const creatingDocument = qraft.entities.postEntitiesIdDocuments.useIsMutating({
path: {
entity_id: '1',
},
});
const creatingDocumentTotal = qraft.entities.postEntitiesIdDocuments.useIsMutating();
return (
<>
{!!creatingDocumentTotal && <div>Number of creating documents: {creatingDocumentTotal}...</div>}
{!!creatingDocument && <div>Creating document...</div>}
</>
);
}