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