(
options:
| MutationStateOptions<TResult, TMutation>
| (() => MutationStateOptions<TResult, TMutation>) = {},
queryClient?: QueryClient,
)
| 87 | } |
| 88 | |
| 89 | export 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 | } |
no test coverage detected