* 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)
| 471 | * ``` |
| 472 | */ |
| 473 | isStaleByTime(staleTime: StaleTime = 0): boolean { |
| 474 | // no data is always stale |
| 475 | if (this.state.data === undefined) { |
| 476 | return true |
| 477 | } |
| 478 | // static is never stale |
| 479 | if (staleTime === 'static') { |
| 480 | return false |
| 481 | } |
| 482 | // if the query is invalidated, it is stale |
| 483 | if (this.state.isInvalidated) { |
| 484 | return true |
| 485 | } |
| 486 | |
| 487 | return !timeUntilStale(this.state.dataUpdatedAt, staleTime) |
| 488 | } |
| 489 | |
| 490 | /** @internal */ |
| 491 | onFocus(): void { |
no test coverage detected