useInfiniteScroll
Loads paginated data as the user nears the end of a list. An IntersectionObserver watches a sentinel after the last item and loads the next page while it is in view, re-checking after every page so a short page never stalls the list.
Install: pnpm add-composable useInfiniteScroll
Infinite list
Scroll the box. Reset while a page is loading: the late page is dropped, so the list starts again from page 1 with nothing repeated.
API
fetch((page, { signal }) => Promise<T[]>): Option. Loads one page (1-based). signal aborts when reset() runs or the owner unmounts.pageSize(number): Option. A page shorter than this means there is no more data.threshold(number): Option. How far before the end, in px, the next page starts loading.window(boolean): Option. Measure against the window, for a list the page itself scrolls.items(Ref<T[]>): Every loaded item, in page order.loading(Ref<boolean>): A page is in flight.done(Ref<boolean>): The last page came back shorter than pageSize.error(Ref<string | null>): The last failure. The page is kept, so loadMore() retries it.containerRef(Ref<HTMLElement | null>): The scroller (with window: true, just the list).sentinelRef(Ref<HTMLElement | null>): Optional element placed after the items. Without one, a 1px div is appended and kept last.loadMore(() => Promise<void>): Loads the next page now. Does nothing while loading or done.reset(() => void): Aborts the request in flight, clears the list and loads page 1. A page that lands late is dropped.