Dev Helpers

React / Lists and collections

Alphabetized directory

Dev Helpers · August 27, 2026

A directory benefits from a locale-aware sort and an unchanged input array. Sorting a prop in place can reorder data owned by a parent component.

Worked example

// components/AlphabetizedDirectory.tsx

export default function AlphabetizedDirectory({
  items = ["Oak", "Pine", "Maple"],
}: { items?: string[] } = {}) {
  const sorted = [...items].sort((a, b) => a.localeCompare(b));
  return (
    <ol>
      {sorted.map((v, i) => (
        <li key={i}>{v}</li>
      ))}
    </ol>
  );
}

Implementation notes

Stable keys should identify entries independently of their alphabetical position. Otherwise reordering can move local component state to another person.

Try it yourself

Render accented and mixed-case labels and compare the parent list afterward.

Open the React example →

Editorial date August 27, 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.