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

Function shouldLoadOnMount

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

* Checks whether a query has no data yet and should do its initial load when an observer mounts. * @param query - The query to check. * @param options - The observer options. * @returns `true` if the query is enabled, has no data, and isn't in an error state with * `retryOnMount: false`.

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

Source from the content-addressed store, hash-verified

875 * `retryOnMount: false`.
876 */
877function shouldLoadOnMount(
878 query: Query<any, any, any, any>,
879 options: QueryObserverOptions<any, any, any, any>,
880): boolean {
881 return (
882 resolveQueryValue(options.enabled, query) !== false &&
883 query.state.data === undefined &&
884 !(
885 query.state.status === 'error' &&
886 resolveQueryValue(options.retryOnMount, query) === false
887 )
888 )
889}
890
891/**
892 * Checks whether a query should fetch when an observer mounts: either for its initial load, or

Callers 1

shouldFetchOnMountFunction · 0.85

Calls 1

resolveQueryValueFunction · 0.90

Tested by

no test coverage detected