Beta

Lazy Load / Infinite Scroll Container

Infinite scroll container for optimizing the loading of large data sets, with a customizable threshold and a configurable loading indicator.

Installation

Usage

const [items, setItems] = React.useState<string[]>([]);
const [isPending, setIsPending] = React.useState(false);
const [itemsCount, setItemsCount] = React.useState<number | null | undefined>(
  null,
);

const loadMore = React.useCallback(() => {
  setIsPending(true);
  setTimeout(() => {
    setItems((prev) => [...prev, ...Array(10).fill('item')]);
    setItemsCount(items.length);
    setIsPending(false);
  }, 1000);
}, []);

return (
  <ContainerInfiniteScroll
    items={items}
    isPending={isPending}
    itemsCount={itemsCount}
    loadMore={loadMore}
  >
    {items.map((item, index) => (
      <div key={index}>{item}</div>
    ))}
  </ContainerInfiniteScroll>
);

Props

ContainerInfiniteScroll

PropTypeDefault
Loader?
React.ComponentType | React.ReactElement
Spinner
loadMore
() => void
-
itemsCount
number | null | undefined
-
isPending
boolean
-
items
unknown[]
-

CellInfiniteScroll

PropTypeDefault
SkeltonComp?
React.ComponentType | React.ReactElement
SkeltonWrapper
isPending
boolean
-