Phân trang

Hook hỗ trợ trang dựa trên IntersectionObserver / cuộn vô hạn.


useListPagingForSentinel

Gắn ref vào mục đầu tiên/cuối cùng và kích hoạt gọi trang trước/sau khi vào 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

usePagingHandlerchỉ thực hiện scrollIntoView cho các trang đã tải và giúp gọi callback fetch cho các trang không có.

tsx
const dataListRef = useRef<Array<Item[] | null>>([]);
const { setPaginationRef, handleReachTerminal, handleClickPageChange } =
  usePagingHandler<Item>({
    lastCallPageNumber: 0,
    dataListRef,
  });
© 2026 Byeolnaerim. Bảo lưu mọi quyền.Giới thiệuChính sách xử lý thông tin cá nhân