Skip to content

Commit 0ad9168

Browse files
committed
fix(hasPageParam): look for (undefined | null | false) values
1 parent d2ba877 commit 0ad9168

File tree

1 file changed

+29
-17
lines changed

1 file changed

+29
-17
lines changed

src/core/infiniteQueryBehavior.ts

Lines changed: 29 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -43,15 +43,14 @@ export function infiniteQueryBehavior<
4343
cancelFn = (queryFnResult as any).cancel
4444
}
4545

46-
const promise = Promise.resolve(queryFnResult)
47-
.then(page => {
48-
newPageParams = previous
49-
? [param, ...newPageParams]
50-
: [...newPageParams, param]
51-
return previous ? [page, ...pages] : [...pages, page]
52-
})
46+
const promise = Promise.resolve(queryFnResult).then(page => {
47+
newPageParams = previous
48+
? [param, ...newPageParams]
49+
: [...newPageParams, param]
50+
return previous ? [page, ...pages] : [...pages, page]
51+
})
5352
if (cancelFn) {
54-
(promise as any).cancel = cancelFn
53+
;(promise as any).cancel = cancelFn
5554
}
5655
return promise
5756
}
@@ -101,11 +100,14 @@ export function infiniteQueryBehavior<
101100
}
102101
}
103102

104-
const finalPromise = promise.then(pages => ({ pages, pageParams: newPageParams }))
103+
const finalPromise = promise.then(pages => ({
104+
pages,
105+
pageParams: newPageParams,
106+
}))
105107
if ((promise as any).cancel) {
106-
(finalPromise as any).cancel = (promise as any).cancel;
108+
;(finalPromise as any).cancel = (promise as any).cancel
107109
}
108-
return finalPromise;
110+
return finalPromise
109111
}
110112
},
111113
}
@@ -133,9 +135,14 @@ export function hasNextPage(
133135
options: QueryOptions<any, any>,
134136
pages?: unknown
135137
): boolean | undefined {
136-
return options.getNextPageParam && Array.isArray(pages)
137-
? typeof getNextPageParam(options, pages) !== 'undefined'
138-
: undefined
138+
if (options.getNextPageParam && Array.isArray(pages)) {
139+
const nextPageParam = getNextPageParam(options, pages)
140+
return (
141+
typeof nextPageParam !== 'undefined' &&
142+
nextPageParam !== null &&
143+
nextPageParam !== false
144+
)
145+
}
139146
}
140147

141148
/**
@@ -146,7 +153,12 @@ export function hasPreviousPage(
146153
options: QueryOptions<any, any>,
147154
pages?: unknown
148155
): boolean | undefined {
149-
return options.getPreviousPageParam && Array.isArray(pages)
150-
? typeof getPreviousPageParam(options, pages) !== 'undefined'
151-
: undefined
156+
if (options.getPreviousPageParam && Array.isArray(pages)) {
157+
const previousPageParam = getPreviousPageParam(options, pages)
158+
return (
159+
typeof previousPageParam !== 'undefined' &&
160+
previousPageParam !== null &&
161+
previousPageParam !== false
162+
)
163+
}
152164
}

0 commit comments

Comments
 (0)