Infinite Scroll
A list that loads the next page as the reader nears its end, with loading, end and error states.
- Category
- Data & feedback
- Access
- Free with an account
- Source
- 129 lines · one file
- States
- 5 drawn
The decision inside it
A Load more button for people who do not scroll
Keyboard and screen-reader users get a real button after the list, hidden until focused, and loading and the end are announced.
When to use it
Use Infinite Scroll for long feeds people browse rather than search: activity, history, a gallery. Pass hasMore and loading from your data hook. For tables people jump around in, use Pagination.
Installation
How you get it
Paste this into Claude Code, Cursor, Codex or any coding agent. It installs the file and uses it as it is, instead of writing a new one.
Use Liro's Infinite Scroll for this.
Install it: npx shadcn@latest add @liro/infinite-scroll
(the @liro registry is set up in components.json, with LIRO_KEY in .env.local)
Import it from @/components/ui/infinite-scroll.
Do not rewrite or restyle it. Pass my data through its props
and keep its built-in states.For the full brief with every prop and the mistakes assistants usually make, use Copy prompt above. Free components install through the @liro registry with your CLI token: see the Namespaced tab.
Usage
import { InfiniteScroll } from "@/components/ui/infinite-scroll";
export function ActivityFeed({ items, hasMore, loading, next }: { items: { id: string; text: string }[]; hasMore: boolean; loading: boolean; next: () => void }) {
return (
<InfiniteScroll hasMore={hasMore} loading={loading} onLoadMore={next}>
<ul>
{items.map((i) => (
<li key={i.id}>{i.text}</li>
))}
</ul>
</InfiniteScroll>
);
}API reference
“Copy prompt” above puts a full brief on your clipboard, install command, dependencies, props, and the mistakes an assistant usually makes with this component.
Props
Read from the component’s own TypeScript interface when the site is built, so this table cannot drift from the file you install.
| Type | Notes | ||
|---|---|---|---|
hasMore | boolean | Yes | More pages exist. |
loading | boolean | Yes | A page is on its way. |
onLoadMore | () => void | Promise<void> | Yes | Ask for the next page. |
threshold | number | No | Pixels before the end to start loading. Default 300. |
loader | React.ReactNode | No | Shown while loading. Default a spinner and "Loading more". |
endMessage | React.ReactNode | No | Shown when there is nothing more. Default "You’re all caught up". |
error | string | No | A failure message; shows Retry. |
onRetry | () => void | No | – |
root | React.RefObject<HTMLElement | null> | No | The scrolling element, when the list scrolls inside a panel. Default the page. |
loadMoreLabel | string | No | The button text for keyboard and screen-reader users. Default "Load more". |
children | React.ReactNode | Yes | – |
Dependencies
npm packages
clsxlucide-reacttailwind-mergeLiro foundations, installed alongside it
liro-themeStates
All of them are drawn by the component. None is left for you to design.
- Loading
- Loaded
- Error with retry
- End of list
- Inside a panel
Accessibility
- Keyboard reachable throughout, in visual order
- Focus trapped in overlays, Escape closes them
- Focus returns to whatever opened it
- Live regions announce what changed, not that something did
- Honours prefers-reduced-motion
Responsive behavior
- Sizes to its container, not the viewport
- Usable from 320px up
- Pointer-based interaction, so trackpad and touch both work
- No hover-only affordances