Course map
Stage 1: Foundation
Stage 2: Intermediate
Stage 3: Advanced
Stage 4: Routing and Application Architecture
Stage 5: Specialization (pick ONE)

Part 04 / Topic 2 of 8

Why key exists, and what it is not

Every element returned from .map() above needs a key prop - a string or number, unique among its siblings. key is not a styling hook and it never reaches the DOM as an attribute; it exists purely so React can answer one question across a re-render: "is this the same logical item as before, or a different one?"

Leave key out, and a static, one-time render like section 1's still works - but a real React app's console tells you anyway, because the next render might not be static. examples/01_menu_list_map.jsx also exports a demonstration-only MenuListMissingKey with no key at all. Rendering it, and actually reading console.error (not guessing at the message), gives this real warning (React 19.3.1, examples/01_menu_list_map.test.jsx):

Each child in a list should have a unique "key" prop.%s%s See https://react.dev/link/warning-keys for more information.
Check the render method of `MenuListMissingKey`.

(%s%s is React's own warning-template placeholder left unfilled when no extra detail applies here - a real artifact of the warning, not a typo in this lesson.) item.id in section 1's MenuList is a stable key: the same dish keeps the same id no matter what else in the array changes around it. Section 3 shows exactly what goes wrong when the key is stable-looking but is not - the array index.

Done here? The practice set for Part 4 — including the solutions — is on the part page.

Search the guide