The communications platform that puts data protection first.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
Rocket.Chat/apps/meteor/client/components/GenericTable/hooks/usePagination.ts

37 lines
1.2 KiB

import { useEffect, useMemo } from 'react';
import { useCurrent } from './useCurrent';
import { useItemsPerPage } from './useItemsPerPage';
import { useItemsPerPageLabel } from './useItemsPerPageLabel';
import { useShowingResultsLabel } from './useShowingResultsLabel';
export const usePagination = (): {
current: ReturnType<typeof useCurrent>[0];
setCurrent: ReturnType<typeof useCurrent>[1];
itemsPerPage: ReturnType<typeof useItemsPerPage>[0];
setItemsPerPage: ReturnType<typeof useItemsPerPage>[1];
itemsPerPageLabel: ReturnType<typeof useItemsPerPageLabel>;
showingResultsLabel: ReturnType<typeof useShowingResultsLabel>;
} => {
const [itemsPerPage, setItemsPerPage] = useItemsPerPage();
const [current, setCurrent] = useCurrent();
const itemsPerPageLabel = useItemsPerPageLabel();
const showingResultsLabel = useShowingResultsLabel();
// Reset to first page when itemsPerPage changes
useEffect(() => {
setCurrent(0);
}, [itemsPerPage, setCurrent]);
return useMemo(
() => ({
itemsPerPage,
setItemsPerPage,
current,
setCurrent,
itemsPerPageLabel,
showingResultsLabel,
}),
[itemsPerPage, setItemsPerPage, current, setCurrent, itemsPerPageLabel, showingResultsLabel],
);
};