Dev Helpers

React / Commerce

Stock availability label

Dev Helpers · May 2, 2026

An availability label derives from inventory and any reservation policy. Keep the visible wording consistent with the action a visitor can actually take.

Worked example

// components/StockAvailabilityLabel.tsx

export default function StockAvailabilityLabel({ stock = 8 }: { stock?: number } = {}) {
  return (
    <span role="status">
      {stock === 0 ? "Sold out" : stock < 4 ? "Only " + stock + " left" : "In stock"}
    </span>
  );
}

Implementation notes

An item can have positive stock while being unavailable for sale. Separate raw quantity from availability when reservations or release dates are involved.

Try it yourself

Compare zero stock, low stock and a quantity already reserved.

Open the React example →

Editorial date May 2, 2026 · Published December 6, 2026

Related articles

Percentage meter

A percentage meter needs both a bounded visual fill and a meaningful textual value. Handle a zero denominator before dividing.

Vertical typesetting sample

Vertical typesetting changes the reading direction and available inline space. Treat the sample text as content so it remains selectable and accessible.

Square cover crop

A square image crop gives a card grid consistent geometry. The crop anchor determines whether the most important part of a photo survives.