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

Method isStaleByTime

packages/query-core/src/query.ts:567–582  ·  view source on GitHub ↗

* Returns `true` if the query's data is stale relative to the given * `staleTime` (defaults to `0`). * - A query with no data is always stale. * - `staleTime: 'static'` is never stale. * - An invalidated query is always stale. * - Otherwise, staleness is based on elapsed time since `d

(staleTime: StaleTime = 0)

Source from the content-addressed store, hash-verified

565 * ```
566 */
567 isStaleByTime(staleTime: StaleTime = 0): boolean {
568 // no data is always stale
569 if (this.state.data === undefined) {
570 return true
571 }
572 // static is never stale
573 if (staleTime === 'static') {
574 return false
575 }
576 // if the query is invalidated, it is stale
577 if (this.state.isInvalidated) {
578 return true
579 }
580
581 return !timeUntilStale(this.state.dataUpdatedAt, staleTime)
582 }
583
584 /**
585 * Refetches the query when the window regains focus, if an observer wants that, and continues a

Callers 5

ensureQueryDataMethod · 0.80
queryMethod · 0.80
fetchQueryMethod · 0.80
isStaleFunction · 0.80
query.test-d.tsxFile · 0.80

Calls 1

timeUntilStaleFunction · 0.90

Tested by

no test coverage detected