Paging
IntersectionObserver based page/infinite scroll auxiliary hook.
useListPagingForSentinel
Inserts refs on the first/last item and triggers previous/next page calls when entering the viewport.
tsx
const { firstChildRef, lastChildRef } = useListPagingForSentinel<HTMLDivElement>({
onReachTerminal: ({ isFirst, isLast }) => {
if (isFirst) loadPreviousPage();
if (isLast) loadNextPage();
},
});
return items.map((item, index) => (
<div
key={item.id}
ref={
index === 0
? firstChildRef
: index === items.length - 1
? lastChildRef
: undefined
}
>
{item.name}
</div>
));usePaginationViewNumber
showCurrentPageNumber
현재 보이는 페이지 번호입니다.
showCurrentPageObserveTarget
data-page-index를 가진 페이지 wrapper에 연결하는 observe ref입니다.
usePagingHandler
usePagingHandlerperforms scrollIntoView for already loaded pages and helps call fetch callback for non-existent pages.
tsx
const dataListRef = useRef<Array<Item[] | null>>([]);
const { setPaginationRef, handleReachTerminal, handleClickPageChange } =
usePagingHandler<Item>({
lastCallPageNumber: 0,
dataListRef,
});