Skip to content

Commit e341162

Browse files
add resetDependencies param to usePagination
1 parent 14df943 commit e341162

3 files changed

Lines changed: 6 additions & 5 deletions

File tree

apps/meteor/client/views/admin/customEmoji/CustomEmoji.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ const CustomEmoji = ({ onClick, reload }: CustomEmojiProps) => {
2929

3030
const [text, setText] = useState('');
3131
const { sortBy, sortDirection, setSort } = useSort<'name'>('name');
32-
const { current, itemsPerPage, setItemsPerPage: onSetItemsPerPage, setCurrent: onSetCurrent, ...paginationProps } = usePagination();
32+
const { current, itemsPerPage, setItemsPerPage: onSetItemsPerPage, setCurrent: onSetCurrent, ...paginationProps } = usePagination([text]);
3333

3434
const query = useDebouncedValue(
3535
useMemo(

apps/meteor/client/views/admin/customSounds/CustomSoundsTable/CustomSoundsTable.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,8 @@ type CustomSoundsTableProps = {
2626
const CustomSoundsTable = ({ reload, onClick }: CustomSoundsTableProps) => {
2727
const t = useTranslation();
2828
const { sortBy, sortDirection, setSort } = useSort<'name'>('name');
29-
const { current, itemsPerPage, setItemsPerPage: onSetItemsPerPage, setCurrent: onSetCurrent, ...paginationProps } = usePagination();
30-
3129
const [text, setText] = useState('');
30+
const { current, itemsPerPage, setItemsPerPage: onSetItemsPerPage, setCurrent: onSetCurrent, ...paginationProps } = usePagination([text]);
3231

3332
const query = useDebouncedValue(
3433
useMemo(

packages/ui-client/src/components/GenericTable/hooks/usePagination.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@ import { useShowingResultsLabel } from './useShowingResultsLabel';
88
/**
99
* TODO: Move `usePagination` outside from `GenericTable` folder
1010
*/
11-
export const usePagination = (): {
11+
export const usePagination = (
12+
resetDependencies: unknown[] = [],
13+
): {
1214
current: ReturnType<typeof useCurrent>[0];
1315
setCurrent: ReturnType<typeof useCurrent>[1];
1416
itemsPerPage: ReturnType<typeof useItemsPerPage>[0];
@@ -24,7 +26,7 @@ export const usePagination = (): {
2426
// Reset to first page when itemsPerPage changes
2527
useEffect(() => {
2628
setCurrent(0);
27-
}, [itemsPerPage, setCurrent]);
29+
}, [itemsPerPage, setCurrent, ...resetDependencies]);
2830

2931
return useMemo(
3032
() => ({

0 commit comments

Comments
 (0)