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

Function shouldLoadOnMount

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

879 * `retryOnMount: false`.
880 */
881function shouldLoadOnMount(
882 query: Query<any, any, any, any>,
883 options: QueryObserverOptions<any, any, any, any>,
884): boolean {
885 return (
886 resolveQueryValue(options.enabled, query) !== false &&
887 query.state.data === undefined &&
888 !(
889 query.state.status === 'error' &&
890 resolveQueryValue(options.retryOnMount, query) === false
891 )
892 )
893}
894
895/**
896 * 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