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

Method cancelQueries

packages/query-core/src/queryClient.ts:441–454  ·  view source on GitHub ↗

* Cancels outgoing fetches for queries matching the given filters. Most useful when performing * optimistic updates, since any outgoing refetch that resolves afterwards would otherwise * overwrite the optimistic update. By default (`revert: true`), a cancelled query's data is * reverted to

(
    filters?: QueryFilters<TTaggedQueryKey>,
    cancelOptions: CancelOptions = {},
  )

Source from the content-addressed store, hash-verified

439 * ```
440 */
441 cancelQueries<TTaggedQueryKey extends QueryKey = QueryKey>(
442 filters?: QueryFilters<TTaggedQueryKey>,
443 cancelOptions: CancelOptions = {},
444 ): Promise<void> {
445 const defaultedCancelOptions = { revert: true, ...cancelOptions }
446
447 const promises = notifyManager.batch(() =>
448 this.#queryCache
449 .findAll(filters)
450 .map((query) => query.cancel(defaultedCancelOptions)),
451 )
452
453 return Promise.all(promises).then(noop).catch(noop)
454 }
455
456 /**
457 * Marks queries matching the given filters as invalidated. Unlike

Callers 15

WithKnownParametersFunction · 0.45
WithIdentifiersFunction · 0.45
WithKnownParametersFunction · 0.45
WithIdentifiersFunction · 0.45
ExampleWithUnknownKeyFunction · 0.45
ExamplesFunction · 0.45
ExamplesFunction · 0.45
ExamplesFunction · 0.45
ExamplesFunction · 0.45
ExamplesFunction · 0.45

Calls 2

cancelMethod · 0.80
findAllMethod · 0.45

Tested by

no test coverage detected