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

Function shouldFetchOptionally

packages/query-core/src/queryObserver.ts:949–961  ·  view source on GitHub ↗

* Checks whether a query should fetch after the observer's options change. * @param query - The query observed with the new options. * @param prevQuery - The query observed with the previous options. * @param options - The new observer options. * @param prevOptions - The previous observer option

(
  query: Query<any, any, any, any>,
  prevQuery: Query<any, any, any, any>,
  options: QueryObserverOptions<any, any, any, any, any>,
  prevOptions: QueryObserverOptions<any, any, any, any, any>,
)

Source from the content-addressed store, hash-verified

947 * error state, and it is stale.
948 */
949function shouldFetchOptionally(
950 query: Query<any, any, any, any>,
951 prevQuery: Query<any, any, any, any>,
952 options: QueryObserverOptions<any, any, any, any, any>,
953 prevOptions: QueryObserverOptions<any, any, any, any, any>,
954): boolean {
955 return (
956 (query !== prevQuery ||
957 resolveQueryValue(prevOptions.enabled, query) === false) &&
958 (!options.suspense || query.state.status !== 'error') &&
959 isStale(query, options)
960 )
961}
962
963/**
964 * Checks whether a query is stale for the given observer options.

Callers 2

setOptionsMethod · 0.85
createResultMethod · 0.85

Calls 2

resolveQueryValueFunction · 0.90
isStaleFunction · 0.85

Tested by

no test coverage detected