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 = api.<service>.<operation>.useIsMutating(
filters
)
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
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
import { requestFn } from '@openapi-qraft/react';
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
const queryClient = new QueryClient();
const api = createAPIClient({
requestFn,
queryClient,
baseUrl: 'https://api.sandbox.monite.com/v1',
});
function DocumentsUploadStatus() {
const creatingDocument = api.entities.postEntitiesIdDocuments.useIsMutating({
path: {
entity_id: '1',
},
});
const creatingDocumentTotal = api.entities.postEntitiesIdDocuments.useIsMutating();
return (
<>
{!!creatingDocumentTotal && <div>Number of creating documents: {creatingDocumentTotal}...</div>}
{!!creatingDocument && <div>Creating document...</div>}
</>
);
}
export default function App() {
return (
<QueryClientProvider client={queryClient}>
<DocumentsUploadStatus />
</QueryClientProvider>
);
}