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

Function shouldFetchOptionally

packages/query-core/src/queryObserver.ts:945–957  ·  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

943 * error state, and it is stale.
944 */
945function shouldFetchOptionally(
946 query: Query<any, any, any, any>,
947 prevQuery: Query<any, any, any, any>,
948 options: QueryObserverOptions<any, any, any, any, any>,
949 prevOptions: QueryObserverOptions<any, any, any, any, any>,
950): boolean {
951 return (
952 (query !== prevQuery ||
953 resolveQueryValue(prevOptions.enabled, query) === false) &&
954 (!options.suspense || query.state.status !== 'error') &&
955 isStale(query, options)
956 )
957}
958
959/**
960 * 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