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

Stable IDs: The Gold Standard for Keys

Why unique, stable IDs from your data source are the safest and most reliable choice for keys in most cases.

Stable IDs: The Gold Standard for Keys

What you'll learn: Why unique, stable IDs from your data source are the safest and most reliable choice for keys in most real-world scenarios.


When rendering lists in React, the absolute best practice is to use IDs that come directly from your data source—typically from your backend database. These IDs are naturally unique, never change for a given item, and represent the true identity of your data.

Why Data-Source IDs Are Gold

Think of database IDs like Social Security numbers: they're assigned once, never change, and uniquely identify an entity for its entire lifetime. When you use these as React keys, you're giving React the most reliable information possible about which items are which across renders.

// ✅ GOLD STANDARD: Use stable IDs from your data
const users = [
  { id: 'usr_123abc', name: 'Alice' },
  { id: 'usr_456def', name: 'Bob' },
  { id: 'usr_789ghi', name: 'Charlie' }
];

return (
  <ul>
    {users.map(user => (
      <li key={user.id}>{user.name}</li>
    ))}
  </ul>
);

Benefits Over Other Approaches

Unlike array indices (which change when items reorder) or client-generated keys (which can have edge cases), data-source IDs are:

  • Truly unique across your entire dataset
  • Stable regardless of sorting, filtering, or reordering
  • Persistent across page reloads and API refetches
  • Meaningful for debugging (you can trace them back to your database)

When This Applies

Anytime you're rendering data from an API, database, or any persistent storage, those IDs should be your first choice. This includes user lists, product catalogs, comments, posts—essentially any domain entity.

Key Takeaway: When your data has unique IDs from its source (database, API), always use those as keys—they're the most reliable, stable identifiers React can work with.