Course contentsShow
← React
Lesson 1257 of 2,39632. Lists and Keys Deep DiveFree lesson

Index Keys in Read-Only Lists

Rendering static content like blog posts or documentation where list order never changes makes index acceptable.

Index Keys in Read-Only Lists

You'll learn: When using array indexes as keys is actually perfectly safe and acceptable in React.

The Exception to the Anti-Index Rule

You've learned that index keys are usually problematic because they break React's ability to track items when lists change. But there's an important exception: static, read-only lists.

If your list never changes—no additions, deletions, reordering, or updates—then indexes are stable identifiers. They won't point to different items across renders because the items literally never move.

Common Safe Use Cases

Think of content that's truly fixed:

  • Blog post archives (year-by-year lists that don't change)
  • Documentation navigation (static chapter lists)
  • Privacy policy sections (numbered clauses that never reorder)
  • Historical records (past event timelines)
  • Static configuration displays (showing hardcoded options)

These aren't dynamic lists where users add/remove items. They're static content rendered once with no interaction that changes the list structure.

The Analogy

It's like numbering chapters in a published book. Once printed, chapter 5 will always be chapter 5. The index is stable. In contrast, a shopping cart is like a draft manuscript where chapters get added, removed, and reordered—indexes would point to different content.

The Practical Reality

If you're rendering a hardcoded array that lives in your source code and never changes at runtime, an index key works fine:

const TERMS = ['Privacy', 'Security', 'Cookies'];
// This list never changes, index is safe

But if that array can ever be filtered, sorted, or modified—even potentially—use proper IDs.

Key Takeaway: Index keys are acceptable when rendering truly static content where the list order and items will never change during the application's lifetime.