Skip to content

Commit 0059050

Browse files
committed
fix: bug on infinity dataloader
1 parent ae89fc2 commit 0059050

File tree

1 file changed

+6
-9
lines changed

1 file changed

+6
-9
lines changed

packages/use-dataloader/src/useInfiniteDataLoader.ts

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -55,17 +55,12 @@ export const useInfiniteDataLoader = <
5555
getNextPage ? getNextPage(...params) : undefined,
5656
)
5757

58-
const paramsRef = useRef({
59-
...baseParams,
60-
[pageParamKey]: page,
61-
})
62-
63-
paramsRef.current = {
58+
const paramsArgs = {
6459
...baseParams,
6560
[pageParamKey]: page,
6661
}
6762

68-
const getMethodRef = useRef(() => method(paramsRef.current))
63+
const getMethodRef = useRef(() => method(paramsArgs))
6964
const getOnSuccessRef = useRef(
7065
(...params: Parameters<NonNullable<typeof onSuccess>>) =>
7166
onSuccess?.(...params),
@@ -190,7 +185,8 @@ export const useInfiniteDataLoader = <
190185
})
191186

192187
useEffect(() => {
193-
request.method = () => method(paramsRef.current)
188+
request.method = () => method(paramsArgs)
189+
// eslint-disable-next-line react-hooks/exhaustive-deps
194190
}, [method, request])
195191

196192
useEffect(() => {
@@ -215,13 +211,14 @@ export const useInfiniteDataLoader = <
215211
.then(async result => {
216212
nextPageRef.current = getNextPageFnRef.current(
217213
result,
218-
paramsRef.current,
214+
paramsArgs,
219215
) as typeof page
220216
await onSuccessLoad(result)
221217
})
222218
.catch(onFailedLoad)
223219
}
224220
optimisticIsLoadingRef.current = false
221+
// eslint-disable-next-line react-hooks/exhaustive-deps
225222
}, [needLoad, request])
226223

227224
useEffect(() => {

0 commit comments

Comments
 (0)