Infinite Masonry

A masonry grid for feeds of unknown length: it measures each card's real height, renders only what is near the viewport with TanStack Virtual, picks a column count from the container width and fetches the next page before the reader runs out.

Preview

Infinite Masonry preview width

Install

Add it with the shadcn CLI, or copy the source manually.

$ bunx --bun shadcn add @karaui/infinite-masonry
@karaui not found? Add it to components.json
{
  "registries": {
    "@karaui": "https://karaui.kamisama-v0.my.id/r/{name}.json"
  }
}

@karaui is in shadcn's public registry directory, so the latest CLI needs no setup. On an older CLI, merge this into the existing file once and every @karaui/… install resolves.

API Reference

items
readonly T[]
—
getItemKey
(item: T, index: number) => InfiniteMasonryKey
—
renderItem
(item: T, index: number) => ReactNode
—
onLoadMore
() => void | Promise<void>
—
hasMore
boolean
—
loading?
boolean
false
error?
ReactNode
—
onRetry?
(() => void)
—
estimateSize?
((item: T, index: number) => number)
() => 240
renderLoadingItem?
((index: number) => ReactNode)
(index) => <DefaultLoadingItem index={index} />
emptyState?
ReactNode
<DefaultEmptyState />
endState?
ReactNode
—
minColumnWidth?
number
208
maxColumns?
number
4
gap?
number
12
overscan?
number
4
prefetch?
number
3
animateItems?
boolean
true
ariaLabel?
string
Infinite masonry feed
className?
string
—
contentClassName?
string
—
itemClassName?
string
—

Keep in mind

Some components on this site are inspired by or recreated from existing work across the web. I'm not here to take credit; just to learn, experiment, and sometimes push things a bit further. If something looks familiar and I forgot to mention you, reach out and I'll fix that right away.

Updated