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

Function useMutationState

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

Source from the content-addressed store, hash-verified

209 * ```
210 */
211export function useMutationState<
212 TResult = MutationState,
213 TMutation extends Mutation<any, any, any, any> =
214 MutationTypeFromResult<TResult>,
215>(
216 options:
217 | MutationStateOptions<TResult, TMutation>
218 | (() => MutationStateOptions<TResult, TMutation>) = {},
219 queryClient?: QueryClient,
220): Readonly<Ref<Array<TResult>>> {
221 const resolvedOptions = computed(() => {
222 const newOptions = typeof options === 'function' ? options() : options
223 return {
224 filters: cloneDeepUnref(newOptions.filters),
225 select: newOptions.select,
226 }
227 })
228 const mutationCache = (queryClient || useQueryClient()).getMutationCache()
229 const state = shallowRef(getResult(mutationCache, resolvedOptions.value))
230 const unsubscribe = mutationCache.subscribe(() => {
231 state.value = getResult(mutationCache, resolvedOptions.value)
232 })
233
234 watch(resolvedOptions, () => {
235 state.value = getResult(mutationCache, resolvedOptions.value)
236 })
237
238 onScopeDispose(() => {
239 unsubscribe()
240 })
241
242 return shallowReadonly(state)
243}

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