Server-Side
To configure your paginated data for infinite scrolling, you should use theInertia::scroll()method when returning your response. This method automatically configures the proper merge behavior and normalizes pagination metadata for the frontend component.
Inertia::scroll() method works with Laravel’s paginate(), simplePaginate(), and cursorPaginate() methods, as well as pagination data wrapped in Eloquent API resources. For more details, check out the Inertia::scroll() method documentation.
Client-Side
On the client side, Inertia provides the<InfiniteScroll> component to automatically load additional pages of content. The component accepts a data prop that specifies the key of the prop containing your paginated data. The <InfiniteScroll> component should wrap the content that depends on the paginated data.
Loading Buffer
You can control how early content begins loading by setting a buffer distance. The buffer specifies how many pixels before the end of the content loading should begin.URL Synchronization
The infinite scroll component updates the browser URL’s query string (?page=...) as users scroll through content. The URL reflects which page has the most visible items on screen, updating in both directions as users scroll up or down. This allows users to bookmark or share links to specific pages. You can disable this behavior to maintain the original page URL.
Resetting
When filters or other parameters change, you may need to reset the infinite scroll data to start from the beginning. Without resetting, new results will merge with existing content instead of replacing it. You can reset data using thereset visit option.
Loading Direction
The infinite scroll component loads content in both directions when you scroll near the start or end. You can control this behavior using theonly-next and only-previous props.
Reverse Mode
For chat applications, timelines, or interfaces where content is sorted descendingly (newest items at the bottom), you can enable reverse mode. This configures the component to load older content when scrolling upward.:auto-scroll="false".
Manual Mode
Manual mode disables automatic loading when scrolling and allows you to control when content loads through thenext and previous slots. For more details about available slot properties and customization options, see the Slots documentation.
manualAfter prop.
Slots
The infinite scroll component provides several slots to customize the loading experience. These slots allow you to display custom loading indicators and create manual load controls. Each slot receives properties that provide loading state information and functions to trigger content loading.Default Slot
The main content area where you render your data items. This slot receives loading state information.Loading Slot
The loading slot is used as a fallback when loading content and no custombefore or after slots are provided. This creates a default loading indicator.
Previous and Next Slots
Theprevious and next slots are rendered above and below the main content, typically used for manual load controls. These slots receive several properties including loading states, fetch functions, and mode indicators.
loading, previous, and next slots receive the following properties:
| Property | Description |
|---|---|
loading | Whether the slot is currently loading content |
loadingPrevious | Whether previous content is loading |
loadingNext | Whether next content is loading |
fetch | Function to trigger loading for the slot |
hasMore | Whether more content is available for the slot |
hasPrevious | Whether more previous content is available |
hasNext | Whether more next content is available |
manualMode | Whether manual mode is active |
autoMode | Whether automatic loading is active |
Custom Element
TheInfiniteScroll component renders as a <div> element. You may customize this to use any HTML element using the as prop.
Element Targeting
The infinite scroll component automatically tracks content and assigns page numbers to elements for URL synchronization. When your data items are not direct children of the component’s root element, you need to specify which element contains the actual data items using theitemsElement prop.
#table-body element and automatically tags each <tr> with a page number as new content loads. This enables proper URL updates based on which page’s content is most visible in the viewport.
You can also specify custom trigger elements for loading more content using CSS selectors. This prevents the default trigger elements from being rendered and uses intersection observers on your custom elements instead.
Scroll Containers
The infinite scroll component works within any scrollable container, not just the main document. The component automatically adapts to use the custom scroll container for trigger detection and calculations instead of the main document scroll.Multiple Scroll Containers
Sometimes you may need to render multiple infinite scroll components on a single page. However, if both components use the defaultpage query parameter for URL synchronization, they will conflict with each other. To resolve this, instruct each paginator to use a custom pageName.
Inertia::scroll() method automatically detects the pageName from each paginator, allowing both scroll containers to maintain independent pagination state. This results in URLs like ?users=2&orders=3 instead of conflicting ?page= parameters.
For more information about pagination page names, see Laravel’s documentation.
Programmatic Access
When you need to trigger loading actions programmatically, you may use a template ref.fetchNext()- Manually fetch the next pagefetchPrevious()- Manually fetch the previous pagehasNext()- Whether there is a next pagehasPrevious()- Whether there is a previous page
Inertia::scroll() Method
TheInertia::scroll() method provides server-side configuration for infinite scrolling. It automatically configures the proper merge behavior so that new data is appended or prepended to existing content instead of replacing it, and normalizes pagination metadata for the frontend component.
scroll() accepts.
ProvidesScrollMetadata or a callback that returns such an instance. The callback receives the $data parameter. This is useful when integrating with third-party pagination libraries like Fractal.