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

Function useMutationState

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

Source from the content-addressed store, hash-verified

194 * ```
195 */
196export function useMutationState<
197 TResult = MutationState,
198 TMutation extends Mutation<any, any, any, any> =
199 MutationTypeFromResult<TResult>,
200>(
201 options:
202 | MutationStateOptions<TResult, TMutation>
203 | (() => MutationStateOptions<TResult, TMutation>) = {},
204 queryClient?: QueryClient,
205): Readonly<Ref<Array<TResult>>> {
206 const resolvedOptions = computed(() => {
207 const newOptions = typeof options === 'function' ? options() : options
208 return {
209 filters: cloneDeepUnref(newOptions.filters),
210 select: newOptions.select,
211 }
212 })
213 const mutationCache = (queryClient || useQueryClient()).getMutationCache()
214 const state = shallowRef(getResult(mutationCache, resolvedOptions.value))
215 const unsubscribe = mutationCache.subscribe(() => {
216 state.value = getResult(mutationCache, resolvedOptions.value)
217 })
218
219 watch(resolvedOptions, () => {
220 state.value = getResult(mutationCache, resolvedOptions.value)
221 })
222
223 onScopeDispose(() => {
224 unsubscribe()
225 })
226
227 return shallowReadonly(state)
228}

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