Dev Helpers
← Back

Shortest label first

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

Open this example in the interactive library

Live preview

Source code

// components/ShortestLabelFirst.tsx

export default function ShortestLabelFirst({
  entries = ["Beta", "Alpha", "Gamma"],
}: { entries?: string[] } = {}) {
  return (
    <ul>
      {[...entries]
        .sort((a, b) => a.length - b.length)
        .map((v, i) => (
          <li key={i}>
            {v} ({v.length})
          </li>
        ))}
    </ul>
  );
}