Reference

Balanced Props

Props for MasonryBalanced measurement and shortest-column placement.

MasonryBalanced accepts all Common Props plus these measurement props.

PropTypeDefaultNotes
getItemHeight(data: T, index: number, columnWidth: number) => number-Provides known height and skips waiting for DOM measurement.
estimatedItemHeightnumber | ((data: T, index: number, columnWidth: number) => number)150Initial height before a card is measured.
minItemHeightnumber-Clamps measured heights to at least this value.

Known height function

<MasonryBalanced
  items={photos}
  getItemHeight={(photo, _index, columnWidth) =>
    Math.round(columnWidth * (photo.height / photo.width))
  }
  render={MasonryCard}
/>;

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

Return the rendered height in pixels for the current column width.

Estimate strategy

Pick an estimatedItemHeight close to the average card height. A realistic estimate makes the initial layout closer to the measured layout.

Minimum height

Use minItemHeight when a card can briefly measure too small while fonts, media, or async content settle.

Incremental updates and anchoring

  • estimatedItemHeight: a number or (data, index, columnWidth) => number.
  • layoutUpdates: "balanced" (default) rebalances a changed suffix; "stable" retains columns during height updates. Width and column-count changes rebuild positions in either mode.
  • preserveScrollPosition: false by default. Retains a visible keyed card's pixel offset across prepends, height updates, and responsive layout changes.
  • scrollContainer: optional element ref; defaults to window scrolling.

Use stable, unique itemKey values for anchoring and immutable item updates.

On this page