Skip to content

Commit e3bf43f

Browse files
committed
fix: let the refetchInterval function also return undefined
and fall back to false if it does
1 parent fba755a commit e3bf43f

File tree

3 files changed

+10
-8
lines changed

3 files changed

+10
-8
lines changed

docs/react/reference/useQuery.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ const {
101101
- `queryKeyHashFn: (queryKey: QueryKey) => string`
102102
- Optional
103103
- If specified, this function is used to hash the `queryKey` to a string.
104-
- `refetchInterval: number | false | ((data: TData | undefined, query: Query) => number | false)`
104+
- `refetchInterval: number | false | ((data: TData | undefined, query: Query) => number | false | undefined)`
105105
- Optional
106106
- If set to a number, all queries will continuously refetch at this frequency in milliseconds
107107
- If set to a function, the function will be executed with the latest data and query to compute a frequency

packages/query-core/src/queryObserver.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -342,12 +342,14 @@ export class QueryObserver<
342342
}
343343

344344
#computeRefetchInterval() {
345-
return typeof this.options.refetchInterval === 'function'
346-
? this.options.refetchInterval(
347-
this.#currentResult.data,
348-
this.#currentQuery,
349-
)
350-
: this.options.refetchInterval ?? false
345+
return (
346+
(typeof this.options.refetchInterval === 'function'
347+
? this.options.refetchInterval(
348+
this.#currentResult.data,
349+
this.#currentQuery,
350+
)
351+
: this.options.refetchInterval) ?? false
352+
)
351353
}
352354

353355
#updateRefetchInterval(nextInterval: number | false): void {

packages/query-core/src/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ export interface QueryObserverOptions<
202202
| ((
203203
data: TData | undefined,
204204
query: Query<TQueryFnData, TError, TQueryData, TQueryKey>,
205-
) => number | false)
205+
) => number | false | undefined)
206206
/**
207207
* If set to `true`, the query will continue to refetch while their tab/window is in the background.
208208
* Defaults to `false`.

0 commit comments

Comments
 (0)