@usenavii/react

A thin React component on top of @usenavii/core. Memoized; renders the engine output as a data-URI <img> so the SVG is treated as opaque by the browser.

Install

npm i @usenavii/react

@usenavii/core is bundled in; you don't install it separately unless you also use the engine directly.

Usage

import { Navii } from '@usenavii/react';

export function UserChip({ user }) {
  return (
    <Navii
      seed={user.id}
      size={48}
      title={user.name}
      animated
      className="rounded-full"
    />
  );
}

Props

Extends AvatarOptions (see core docs) plus:

PropTypeDescription
seedstringRequired. See the seed rule.
classNamestringClass applied to the <img> element.
styleCSSPropertiesStandard React inline style on the <img>. Note: this is the React DOM style, not the engine's StyleHint — use styleHint below for engine-level bias.
styleHint'masc' | 'femme' | 'neutral'Engine-level style hint (biases seeded picks). Forwarded to AvatarOptions.style. Renamed in React to avoid collision with React's style prop.
altstringAlt text. Falls back to title if omitted.

<NaviiGroup> — overlapping stack

Wraps core's renderGroup(). Common for team rows, contributor lists, attendee piles. Width is computed from size, overlap, and max so the rendered <img> has correct intrinsic dimensions and doesn't shift on load.

import { NaviiGroup } from '@usenavii/react';

<NaviiGroup
  seeds={team.map((u) => u.id)}
  size={48}
  overlap={0.3}        // 0 = no overlap, 0.7 = heavy stack
  max={5}              // overflow collapses into a "+N" counter tile
  ring="#0a0a0b"       // border around each tile
/>

NaviiGroupProps

PropTypeDefaultDescription
seedsstring[]Required. Empty array renders nothing.
sizenumber64Per-tile size in px.
overlapnumber 0–0.70.3Fraction of tile that overlaps previous.
maxnumberallCap before showing a +N counter tile.
ringstring#ffffffBorder color around each tile.
tileBgstring#ffffffFill behind each tile (use 'transparent' to skip).
counterFillstring#E5E7EBBackground of the +N tile.
counterInkstring#374151Text color of the +N tile.
paletteId / palette / mood / background / animated / packs / styleHintForwarded to every tile. Same semantics as <Navii>.

Memoization

The component memoizes the data-URI on seed + all option props via useMemo. This runs on both the server (SSR) and client (hydration), so output is byte-identical between the two renders. Subsequent renders with unchanged props reuse the cached URI without re-running the engine.

If you're rendering a list, ensure your seeds are stable across renders (e.g. user.id, not idx + Date.now()) — otherwise every render rebuilds every avatar.

Re-exports

Top-level @usenavii/core exports re-exported for convenience: createAvatar, selectAvatar, renderAvatar, renderGroup, plus the types AvatarSpec, AvatarOptions, GroupOptions, MoodId, Palette.