Reference

Masonry Props

Props specific to the lightweight Masonry component.

Masonry accepts all Common Props plus these props.

PropTypeDefaultNotes
enableNativebooleanfalseProgressively enables CSS Grid Lanes after hydration when supported.
onLayoutModeChange(mode: MasonryLayoutMode) => void-Reports whether native or fallback layout is active.
columnClassNamestring-Class applied to each internal column wrapper in fallback layout.

Native CSS masonry

<Masonry
  enableNative
  items={items}
  columns={3}
  gap={16}
  render={MasonryCard}
/>;

function MasonryCard({
  data,
}: {
  data: React.ComponentProps<typeof Card>['item'];
}) {
  return <Card item={data} />;
}

enableNative is progressive and opt-in. Masonix detects the standardized display: grid-lanes syntax after hydration. Browsers without support continue using the regular flex layout. Native mode preserves the same fixed track width passed to each renderer.

Use onLayoutModeChange when the interface needs to show which engine is active. The container also exposes the active mode through data-masonix-layout="native" or data-masonix-layout="fallback".

<Masonry
  enableNative
  onLayoutModeChange={(mode) => setLayoutMode(mode)}
  items={items}
  render={MasonryCard}
/>;

function MasonryCard({
  data,
}: {
  data: React.ComponentProps<typeof Card>['item'];
}) {
  return <Card item={data} />;
}

Because browser support is still limited, do not depend on native mode for layout correctness. Treat it as an enhancement and test it in every browser you support.

Column classes

<Masonry
  items={items}
  columns={3}
  columnClassName="space-y-4"
  render={MasonryCard}
/>;

function MasonryCard({
  data,
}: {
  data: React.ComponentProps<typeof Card>['item'];
}) {
  return <Card item={data} />;
}

Use columnClassName for column-level styling only. Use itemClassName or the card component for item styling.

Stateful cards

Set preserveItemState to use the flat measured layout. Keyed cards retain their React state when columns change. This mode ignores columnClassName and enableNative; onLayoutModeChange reports "fallback". Keep the mode unchanged for the lifetime of a mounted grid. The default column-wrapper layout is retained for compatibility.

On this page