Skip to content

Commit

Permalink
fix: let the refetchInterval function also return undefined
Browse files Browse the repository at this point in the history
and fall back to false if it does
  • Loading branch information
TkDodo committed Apr 24, 2023
1 parent fba755a commit e3bf43f
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 8 deletions.
2 changes: 1 addition & 1 deletion docs/react/reference/useQuery.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ const {
- `queryKeyHashFn: (queryKey: QueryKey) => string`
- Optional
- If specified, this function is used to hash the `queryKey` to a string.
- `refetchInterval: number | false | ((data: TData | undefined, query: Query) => number | false)`
- `refetchInterval: number | false | ((data: TData | undefined, query: Query) => number | false | undefined)`
- Optional
- If set to a number, all queries will continuously refetch at this frequency in milliseconds
- If set to a function, the function will be executed with the latest data and query to compute a frequency
Expand Down
14 changes: 8 additions & 6 deletions packages/query-core/src/queryObserver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -342,12 +342,14 @@ export class QueryObserver<
}

#computeRefetchInterval() {
return typeof this.options.refetchInterval === 'function'
? this.options.refetchInterval(
this.#currentResult.data,
this.#currentQuery,
)
: this.options.refetchInterval ?? false
return (
(typeof this.options.refetchInterval === 'function'
? this.options.refetchInterval(
this.#currentResult.data,
this.#currentQuery,
)
: this.options.refetchInterval) ?? false
)
}

#updateRefetchInterval(nextInterval: number | false): void {
Expand Down
2 changes: 1 addition & 1 deletion packages/query-core/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ export interface QueryObserverOptions<
| ((
data: TData | undefined,
query: Query<TQueryFnData, TError, TQueryData, TQueryKey>,
) => number | false)
) => number | false | undefined)
/**
* If set to `true`, the query will continue to refetch while their tab/window is in the background.
* Defaults to `false`.
Expand Down

0 comments on commit e3bf43f

Please sign in to comment.