Skip to main content
Version: 1.x

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

  1. 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 parameters
    • filters.mutationKey: MutationKey will be used for filtering mutations by MutationKey instead of parameters
      • filters.mutationKey and filters.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
  2. queryClient?: QueryClient

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