(
options:
| MutationStateOptions<TResult, TMutation>
| (() => MutationStateOptions<TResult, TMutation>) = {},
queryClient?: QueryClient,
)
| 194 | * ``` |
| 195 | */ |
| 196 | export 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 | } |
no test coverage detected