* feat: apply full width automatically for DataTable * change implementation * load all columns of insights routing table at the same time * update team member list * sticky columns for >= sm * fix type error --------- Co-authored-by: Udit Takkar <53316345+Udit-takkar@users.noreply.github.com>
34 lines
885 B
TypeScript
34 lines
885 B
TypeScript
"use client";
|
|
|
|
import { useCallback, useEffect } from "react";
|
|
|
|
export const useFetchMoreOnBottomReached = ({
|
|
tableContainerRef,
|
|
hasNextPage,
|
|
fetchNextPage,
|
|
isFetching,
|
|
}: {
|
|
tableContainerRef: React.RefObject<HTMLDivElement>;
|
|
hasNextPage: boolean;
|
|
fetchNextPage: () => void;
|
|
isFetching: boolean;
|
|
}) => {
|
|
const fetchMoreOnBottomReached = useCallback(
|
|
(containerRefElement?: HTMLDivElement | null) => {
|
|
if (containerRefElement) {
|
|
const { scrollHeight, scrollTop, clientHeight } = containerRefElement;
|
|
if (scrollHeight - scrollTop - clientHeight < 300 && !isFetching && hasNextPage) {
|
|
fetchNextPage();
|
|
}
|
|
}
|
|
},
|
|
[fetchNextPage, isFetching]
|
|
);
|
|
|
|
useEffect(() => {
|
|
fetchMoreOnBottomReached(tableContainerRef.current);
|
|
}, [fetchMoreOnBottomReached, tableContainerRef]);
|
|
|
|
return fetchMoreOnBottomReached;
|
|
};
|