key Prop
The key prop is a special attribute you give to elements in a list so React can identify which items changed, were added, or were removed. Keys must be unique among siblings and help React update lists efficiently.
React
When you render a list with .map(), React asks you to add a key to each item. The key acts as a stable identity: if two lists are compared, React uses keys to match old elements to new ones instead of guessing.
Good keys are unique and stable, ideally an id that comes from your data. Using the array index as a key is discouraged when items can be reordered, inserted, or deleted, because it can cause React to reuse the wrong elements and produce subtle bugs.
Examples
JSX — Each list item gets a unique key from user.id, so React can track items reliably across re-renders.
const users = [
{ id: 1, name: "Ana" },
{ id: 2, name: "Ben" },
];
function Users() {
return users.map((user) => (
<li key={user.id}>{user.name}</li>
));
}