mugen

API Reference

The mugen public surface.

useMugenVirtualizer(options)

Creates and owns (across renders) the list instance for items — its measurement engine and scroll position. The item type T is inferred from items. Give the returned instance to <MugenVList>.

const  = ({  }); // instance: MugenInstance<Item>

The library never inspects T. Branch on row shape with a switch inside render; you can upgrade T to a union later without touching the engine.

<MugenVList>

<
  ={}
  ={() => .}
  ={() => (
    < ={12}>
      <>{.}</>
    </>
  )}
  ="16px Inter"
  ={22}
/>;
PropTypeDefault
instanceMugenInstance<T>From useMugenVirtualizer.
getKey(item, index) => stringStable key per item.
render(item) => ReactNodeThe row as a primitive tree.
renderTop() => ReactNodeScrollable content before the first row.
renderBottom() => ReactNodeScrollable content after the last row.
fontFontDefault font for every Text.
lineHeightnumberDefault line height (px).
maxWnumber | stringContent width cap (px / rem / named).
letterSpacing / whiteSpace / wordBreakText defaults.
heightnumberfills parentViewport height (px).
initialScroll'top' | 'bottom' | { to: 'index', index, align? }'top'Initial scroll target.
widthnumberResizeObserverOverride the measured width (SSR/tests).
overscannumber200Extra px rendered above/below the viewport.
onTopReached(index) => voidFires once when the scroll enters the top threshold.
onBottomReached(index) => voidFires once when the scroll enters the bottom threshold.
topReachedThreshold / bottomReachedThresholdnumber0Pixel distance from the edge that counts as reached.
className / styleOn the scroll container.

Row hooks

Called inside render. See State & Hooks and Effects.

const [, ] = (); // like useState; set re-measures
const  = (, ); // like useMemo; readable off-screen
(, ); // like useEffect; runs for every row

useMugenState's set and useMugenEffect re-measure the affected row in O(log n). useMugenEffect runs on a microtask after measure, for every row (on- or off-screen); return a cleanup like useEffect.

MugenInstance

.('row-42', { : 'smooth', : 'center' });
.(42);
.; // number of items
.(); // exact scrollable height (px)
const : ScrollToOptions = {
  : 'smooth', // 'auto' | 'smooth'
  : 'center', // 'auto' | 'start' | 'center' | 'end'
};

See Scrolling.

Primitives

Text is the pretext leaf; VStack/HStack are the layout boxes; definePrimitive(tag, { direction? }) makes a measurable box from any HTML tag. style is MeasurableStyle and className is SafeClassName — spacing/sizing through either is a type error. Escape is the exception: a declared-height box whose children are never walked (arbitrary React, e.g. a shadcn tooltip), with unrestricted style/className inside. See Primitives.

Fonts

font (typed Font) and lineHeight are Text props with <MugenVList> defaults; maxW and the other text fields are list-level. See Fonts & Layout.

Advanced / escape hatches

ExportUse
prepareText / measureText / textHeightThe pretext wrapper + cache.
naturalWidth(text, font, opts)Tightest shrink-wrap width.
clearTextCache()Drop the prepare cache.
watchFonts / subscribeFonts / fontEpochFont-load coordination.
assertMeasurableFont(font)Throws on system-ui.

On this page