useInfiniteScroll
Triggers an asynchronous onLoadMore callback when a sentinel element scrolls into view using IntersectionObserver.
Loading preview...
The useInfiniteScroll hook observes a sentinel element with IntersectionObserver, invokes onLoadMore when it enters the viewport (with configurable distance pre-fetching), and prevents duplicate concurrent calls while a page is loading.
Installation
Usage
Examples
Paginated Feed with a Bottom Sentinel
Place an empty sentinel element at the bottom of your list and pass its ref to useInfiniteScroll.
Reverse Infinite Scroll for Chat History
Set direction: "top" and provide a scrollable container root ref to load older messages when the user scrolls near the top.
API Reference
UseInfiniteScrollOptions
Configuration options for intersection root, pre-fetch distance, and pagination state.
Property
Specification
root?uniondefault:browser viewport
Scrollable root container element or ref
Full Signature
rootMargin?stringdefault:'0px 0px 200px 0px'
Margin around the root element used to trigger loading early
Full Signature
threshold?uniondefault:0
Intersection ratio threshold(s) to trigger
onLoadMoreFull Signature
hasMore?uniondefault:true
Whether more items are available to load
Full Signature
enabled?uniondefault:true
Whether the intersection observer is active
Full Signature
UseInfiniteScrollReturn
Loading status and error state returned by the hook.
Property
Specification
isLoadingunion
Whether
onLoadMore is currently executingFull Signature
loadMorefunction
Manually triggers
onLoadMore if not already loading and hasMore is trueFull Signature