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

Function shouldFetchOn

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

* Checks whether a query should fetch for a `refetchOnMount`, `refetchOnWindowFocus`, or * `refetchOnReconnect` option. * @param query - The query to check. * @param options - The observer options. * @param field - The value of the option to check. * @returns `true` if the query is enabled, not

(
  query: Query<any, any, any, any>,
  options: QueryObserverOptions<any, any, any, any, any>,
  field: (typeof options)['refetchOnMount'] &
    (typeof options)['refetchOnWindowFocus'] &
    (typeof options)['refetchOnReconnect'],
)

Source from the content-addressed store, hash-verified

920 * `false` and the query is stale.
921 */
922function shouldFetchOn(
923 query: Query<any, any, any, any>,
924 options: QueryObserverOptions<any, any, any, any, any>,
925 field: (typeof options)['refetchOnMount'] &
926 (typeof options)['refetchOnWindowFocus'] &
927 (typeof options)['refetchOnReconnect'],
928) {
929 if (
930 resolveQueryValue(options.enabled, query) !== false &&
931 resolveQueryValue(options.staleTime, query) !== 'static'
932 ) {
933 const value = resolveQueryValue(field, query)
934
935 return value === 'always' || (value !== false && isStale(query, options))
936 }
937 return false
938}
939
940/**
941 * Checks whether a query should fetch after the observer's options change.

Callers 3

shouldFetchOnMountFunction · 0.85

Calls 2

resolveQueryValueFunction · 0.90
isStaleFunction · 0.85

Tested by

no test coverage detected