UUIDs and Database IDs as Ideal Keys
You'll learn why unique identifiers from your data source are the best choice for React list keys.
The Gold Standard for Keys
When you're rendering data from a database or API, you've already won the key lottery. Database records come with built-in unique identifiers (like id: 123 or userId: "abc-def-789"), and these make perfect React keys because they're stable, unique, and persistent.
Why Database IDs Are Ideal
Think of database IDs like permanent license plate numbers. No matter how many times you rearrange cars in a parking lot, each car keeps its unique plate. React can always identify which car is which.
const users = [
{ id: 42, name: "Alice" },
{ id: 108, name: "Bob" },
{ id: 7, name: "Charlie" }
];
<ul>
{users.map(user => (
<li key={user.id}>{user.name}</li>
))}
</ul>
Even if users get sorted, filtered, or reordered, id: 42 is always Alice. React knows exactly which list item is which.
UUIDs: Client-Side Perfection
Sometimes you generate data on the client before saving it. UUIDs (Universally Unique Identifiers like "550e8400-e29b-41d4-a716-446655440000") are random strings guaranteed to be unique. They're perfect for temporary items:
const tempItem = {
id: crypto.randomUUID(), // Browser-native UUID generation
title: "Draft Post"
};
The Pattern
If your data has an id field, use it as the key. Period. This simple rule eliminates 90% of key-related bugs and performance issues.
Key Takeaway: Database IDs and UUIDs are stable, unique identifiers that give React perfect information for tracking list items—always prefer them over generated or index-based keys.