@@ -55,15 +55,17 @@ export const useInfiniteDataLoader = <
5555 getNextPage ? getNextPage ( ...params ) : undefined ,
5656 )
5757
58- const paramsMemo = useMemo (
59- ( ) => ( {
60- ...baseParams ,
61- [ pageParamKey ] : page ,
62- } ) ,
63- [ baseParams , page , pageParamKey ] ,
64- )
58+ const paramsRef = useRef ( {
59+ ...baseParams ,
60+ [ pageParamKey ] : page ,
61+ } )
62+
63+ paramsRef . current = {
64+ ...baseParams ,
65+ [ pageParamKey ] : page ,
66+ }
6567
66- const getMethodRef = useRef ( ( ) => method ( paramsMemo ) )
68+ const getMethodRef = useRef ( ( ) => method ( paramsRef . current ) )
6769 const getOnSuccessRef = useRef (
6870 ( ...params : Parameters < NonNullable < typeof onSuccess > > ) =>
6971 onSuccess ?.( ...params ) ,
@@ -188,8 +190,8 @@ export const useInfiniteDataLoader = <
188190 } )
189191
190192 useEffect ( ( ) => {
191- request . method = ( ) => method ( paramsMemo )
192- } , [ method , request , paramsMemo ] )
193+ request . method = ( ) => method ( paramsRef . current )
194+ } , [ method , request ] )
193195
194196 useEffect ( ( ) => {
195197 if ( keepPreviousData ) {
@@ -213,14 +215,14 @@ export const useInfiniteDataLoader = <
213215 . then ( async result => {
214216 nextPageRef . current = getNextPageFnRef . current (
215217 result ,
216- paramsMemo ,
218+ paramsRef . current ,
217219 ) as typeof page
218220 await onSuccessLoad ( result )
219221 } )
220222 . catch ( onFailedLoad )
221223 }
222224 optimisticIsLoadingRef . current = false
223- } , [ needLoad , request , paramsMemo ] )
225+ } , [ needLoad , request ] )
224226
225227 useEffect ( ( ) => {
226228 getOnSuccessRef . current = ( ...params ) => onSuccess ?.( ...params )
0 commit comments