Command Palette

Search for a command to run...

Docs
Infinite Scroll

Infinite Scroll

A component which virtualize large element lists

Installation

pnpm dlx shadcn@latest add "https://akasha-ui.pages.dev/r/styles/default/infinite-scroll.json"

Usage

import {
  InfiniteScroll,
  InfiniteScrollList,
} from "<path-to-ui-components>/infinite-scroll";
return (
    <InfiniteScroll
      count={count}
      estimatedHeight={100}
      overScan={10}
      gap={gap}
    >
       <InfiniteScrollList>
        {(index) => {
          return <div>{sentences[index]}</div>;
        }}
    </InfiniteScroll>

Props

NameTypeDescription
countnumberThe total number of items to virtualize.
estimatedHeightnumberEstimated height of each virtual item.
lanesnumberThe number of lanes the list is divided into.
overScannumberThe number of items rendered above and below the visible area. A higher number reduces the chance of blank items during slow rendering but increases the virtualizer's render time.
gapnumberSet's the spacing between items in the virtualized list.
headerReactNodeComponent which is at the top of a virtual list. Including it inside the infinite scroll helps to accurately calculate the scroll restoration position.
hasNextPagebooleanDetermines there is a next page to be fetched in paginated query.
loadingbooleanSignals if a queried data is loading.
loadingIndicatorReactNodeComponent used to represent loading data.
scrollElementTypewindow or elementType of scroll element for the virtualizer, determining whether it's element-based or window-based.
onLoadMore() => voidCallback to load more data.

Scroll Restoration

Usage

import {
  InfiniteScroll,
  InfiniteScrollList,
  ScrollRestoration,
} from "<path-to-ui-components>/infinite-scroll";
return (
    <InfiniteScroll
      count={count}
      estimatedHeight={100}
      overScan={10}
      gap={gap}
    >
      <ScrollRestoration>
       <InfiniteScrollList>
        {(index) => {
          return <div>{sentences[index]}</div>;
        }}
      </ScrollRestoration>
    </InfiniteScroll>

Props

NameTypeDescription
scrollConfigStorageKeystringKey used to store scroll restoration configuration.
lastScrollRestorationKeystringLast scroll restoration prevents scroll restoration unless the user navigates back to the last key they visited.

Examples

Element based scroll

Loading...