fn
useInfiniteScroll
v0.0.14testeddemoTrigger a loader as a scroll container nears one of its edges.
Backed by useScroll for RTL-aware arrived-edge detection: the
distance is folded into that direction's offset, so onLoadMore fires the
moment the edge comes within distance pixels. Re-checks automatically after
each load (so an under-filled container keeps loading) and degrades safely
under SSR and when IntersectionObserver is unavailable.
Example
ts
const { isLoading } = useInfiniteScroll(el, async () => {
items.push(...await fetchNextPage());
}, { distance: 10 });Demo
Loading demo…
Signature
ts
export function useInfiniteScroll<T extends InfiniteScrollElement = InfiniteScrollElement>(
target: MaybeRefOrGetter<T>,
onLoadMore: UseInfiniteScrollLoadMore,
options: UseInfiniteScrollOptions<T> ={ ... }Type Parameters
Textends InfiniteScrollElement= InfiniteScrollElementParameters
| Parameter | Type | Description |
|---|---|---|
target | MaybeRefOrGetter<T> | Scroll container (element ref, getter, window, or document) |
onLoadMore | UseInfiniteScrollLoadMore | Called near the edge; may return a promise |
options? | UseInfiniteScrollOptions<T> | Options |
Returns
UseInfiniteScrollReturn{ isLoading, reset }| Property | Type | Description |
|---|---|---|
isLoading | ComputedRef<boolean> | Whether onLoadMore is currently in flight. |
reset | () => void | Re-run the edge check on the next tick. Call after appending content if the container is still not full and you want to keep loading. |