Open History to see the last commit
1import { computed, onScopeDispose, ref, watch } from 'vue-demi'
2import type { Ref } from 'vue-demi'
3import type { MutationFilters as MF } from '@tanstack/query-core'
4β
5import { useQueryClient } from './useQueryClient'
6import { cloneDeepUnref } from './utils'
7import type { MaybeRefDeep } from './types'
8import type { QueryClient } from './queryClient'
9β
10export type MutationFilters = MaybeRefDeep<MF>
11β
12export function useIsMutating(
13 mutationFilters: MaybeRefDeep<MF> = {},
14 queryClient?: QueryClient,
15): Ref<number> {
16 const filters = computed(() => cloneDeepUnref(mutationFilters))
17 const client = queryClient || useQueryClient()
18β
19 const isMutating = ref(client.isMutating(filters))
20β
21 const unsubscribe = client.getMutationCache().subscribe(() => {
22 isMutating.value = client.isMutating(filters)
23 })
24β
25 watch(
26 filters,
27 () => {
28 isMutating.value = client.isMutating(filters)
29 },
30 { deep: true },
31 )
32β
33 onScopeDispose(() => {
34 unsubscribe()
35 })
36β
37 return isMutating
38}