Skip to content

Commit

Permalink
fix: add missing dependency in useCursorPaginatedFetcher userEffect
Browse files Browse the repository at this point in the history
  • Loading branch information
ChibiBlasphem authored and Pascal-Delange committed Jan 3, 2025
1 parent 5e03365 commit c4bcf44
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions packages/app-builder/src/hooks/useCursorPaginatedFetcher.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { useCallbackRef } from '@app-builder/utils/hooks';
import { type SerializeFrom } from '@remix-run/node';
import { useFetcher } from '@remix-run/react';
import qs from 'qs';
Expand Down Expand Up @@ -28,6 +29,7 @@ export const useCursorPaginatedFetcher = <T, D = T>({
const [previousFetcherData, setPreviousFetcherData] =
useState<SerializeFrom<T> | null>(null);
const [data, setData] = useState(initialData);
const getQueryParamsRef = useCallbackRef(getQueryParams);

const {
state: paginationState,
Expand All @@ -42,11 +44,11 @@ export const useCursorPaginatedFetcher = <T, D = T>({
return;
}

const queryParams = getQueryParams?.(paginationState.cursor) ?? {};
const queryParams = getQueryParamsRef(paginationState.cursor) ?? {};
submit(qs.stringify(queryParams, { skipNulls: true }), {
method: 'GET',
});
}, [paginationState, submit]);
}, [paginationState, submit, getQueryParamsRef]);

const [previousInitialData, setPreviousInitialData] = useState(initialData);
if (initialData !== previousInitialData && paginationState.isPristine) {
Expand Down

0 comments on commit c4bcf44

Please sign in to comment.