The 'Static Read-Only List' Exception
What you'll learn: The one scenario where using array indexes as keys is actually acceptable and won't cause problems.
When Index Keys Are OK
Remember how we've been warning against using array indexes as keys? Well, there's one important exception to that rule: truly static lists that never change.
If your list meets ALL these criteria, index keys are fine:
- The list never reorders – items always appear in the same sequence
- The list never adds or removes items – it's the same length forever
- The items have no state – no input fields, no local component state, nothing that persists
- The data never changes – it's hardcoded or constant
Real-World Example
Think of a list of months in a calendar widget:
const MONTHS = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun',
'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
function MonthList() {
return (
<ul>
{MONTHS.map((month, index) => (
<li key={index}>{month}</li>
))}
</ul>
);
}
This is perfectly safe because those twelve months will never reorder, never change, and never have state attached to them. The index accurately represents each item's permanent position.
Why This Works
When nothing ever changes, React's reconciliation has no opportunity to get confused. The index for "March" will always be 2, and there's no scenario where that causes a mismatch.
Key Takeaway: Index keys are acceptable for hardcoded, static lists that will never reorder, add/remove items, or contain stateful components—but these situations are rare, so when in doubt, use proper IDs.