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

Function shouldFetchOn

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

916 * `false` and the query is stale.
917 */
918function shouldFetchOn(
919 query: Query<any, any, any, any>,
920 options: QueryObserverOptions<any, any, any, any, any>,
921 field: (typeof options)['refetchOnMount'] &
922 (typeof options)['refetchOnWindowFocus'] &
923 (typeof options)['refetchOnReconnect'],
924) {
925 if (
926 resolveQueryValue(options.enabled, query) !== false &&
927 resolveQueryValue(options.staleTime, query) !== 'static'
928 ) {
929 const value = resolveQueryValue(field, query)
930
931 return value === 'always' || (value !== false && isStale(query, options))
932 }
933 return false
934}
935
936/**
937 * 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