Dev Helpers
← Back

Largest bin share

Import and render <LargestBinShare /> in a React project.

Open this example in the interactive library

Live preview

Source code

// components/LargestBinShare.tsx

export default function LargestBinShare({
  counts = [12, 0, 5, 18],
}: { counts?: number[] } = {}) {
  const total = counts.reduce((a, b) => a + b, 0);
  return (
    <p>
      Largest bin holds {total ? ((Math.max(...counts) * 100) / total).toFixed(1) : 0}%
      of stock
    </p>
  );
}