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

Function useMutationState

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

Source from the content-addressed store, hash-verified

87}
88
89export function useMutationState<
90 TResult = MutationState,
91 TMutation extends Mutation<any, any, any, any> =
92 MutationTypeFromResult<TResult>,
93>(
94 options:
95 | MutationStateOptions<TResult, TMutation>
96 | (() => MutationStateOptions<TResult, TMutation>) = {},
97 queryClient?: QueryClient,
98): Readonly<Ref<Array<TResult>>> {
99 const resolvedOptions = computed(() => {
100 const newOptions = typeof options === 'function' ? options() : options
101 return {
102 filters: cloneDeepUnref(newOptions.filters),
103 select: newOptions.select,
104 }
105 })
106 const mutationCache = (queryClient || useQueryClient()).getMutationCache()
107 const state = shallowRef(getResult(mutationCache, resolvedOptions.value))
108 const unsubscribe = mutationCache.subscribe(() => {
109 state.value = getResult(mutationCache, resolvedOptions.value)
110 })
111
112 watch(resolvedOptions, () => {
113 state.value = getResult(mutationCache, resolvedOptions.value)
114 })
115
116 onScopeDispose(() => {
117 unsubscribe()
118 })
119
120 return shallowReadonly(state)
121}

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