MCPcopy Create free account
hub / github.com/TanStack/query / useMutationState

Function useMutationState

packages/vue-query/src/useMutationState.ts:68–96  ·  view source on GitHub ↗
(
  options:
    | MutationStateOptions<TResult>
    | (() => MutationStateOptions<TResult>) = {},
  queryClient?: QueryClient,
)

Source from the content-addressed store, hash-verified

66}
67
68export function useMutationState<TResult = MutationState>(
69 options:
70 | MutationStateOptions<TResult>
71 | (() => MutationStateOptions<TResult>) = {},
72 queryClient?: QueryClient,
73): Readonly<Ref<Array<TResult>>> {
74 const resolvedOptions = computed(() => {
75 const newOptions = typeof options === 'function' ? options() : options
76 return {
77 filters: cloneDeepUnref(newOptions.filters),
78 select: newOptions.select,
79 }
80 })
81 const mutationCache = (queryClient || useQueryClient()).getMutationCache()
82 const state = shallowRef(getResult(mutationCache, resolvedOptions.value))
83 const unsubscribe = mutationCache.subscribe(() => {
84 state.value = getResult(mutationCache, resolvedOptions.value)
85 })
86
87 watch(resolvedOptions, () => {
88 state.value = getResult(mutationCache, resolvedOptions.value)
89 })
90
91 onScopeDispose(() => {
92 unsubscribe()
93 })
94
95 return shallowReadonly(state)
96}

Callers 4

useIsMutatingFunction · 0.70

Calls 7

cloneDeepUnrefFunction · 0.90
useQueryClientFunction · 0.90
getMutationCacheMethod · 0.80
getResultFunction · 0.70
unsubscribeFunction · 0.70
optionsFunction · 0.50
subscribeMethod · 0.45

Tested by

no test coverage detected