Keys Must Be Unique Among Siblings
What you'll learn: Keys only need uniqueness within their immediate array, not across your entire app.
The Sibling-Only Uniqueness Rule
When React requires unique keys for list items, it doesn't mean globally unique across your entire application. Keys must only be unique among their siblings—the other elements in the same array.
Think of keys like house numbers on a street. Two houses on the same street can't both be "123 Main Street," but a house at "123 Main Street" and another at "123 Oak Avenue" create no confusion—they're on different streets.
Same Key in Different Lists? Totally Fine
function Dashboard() {
const activeUsers = [
{ id: 'u1', name: 'Alice' },
{ id: 'u2', name: 'Bob' }
];
const inactiveUsers = [
{ id: 'u1', name: 'Charlie' }, // Same id as Alice—no problem!
{ id: 'u3', name: 'Diana' }
];
return (
<>
<ul>
{activeUsers.map(user => (
<li key={user.id}>{user.name}</li>
))}
</ul>
<ul>
{inactiveUsers.map(user => (
<li key={user.id}>{user.name}</li>
))}
</ul>
</>
);
}
The id: 'u1' appears in both arrays, but each list is independent. React only compares keys within each .map() call.
What Happens with Duplicate Keys?
If you do have duplicates among siblings, React can't reliably track which component is which. You'll get a console warning, and you might see items rendering incorrectly, state bleeding between components, or elements not updating when they should.
Key Takeaway: Keys must be unique only within their sibling array—different arrays can reuse the same keys without conflict, but duplicates in the same list break React's reconciliation.