Rendering Multiple Items
Watch the walkthrough
Open on InstagramQuick revision
Transform an array into UI with map; use filter when only some records should be shown. A callback with a block body needs an explicit return. Each element directly produced by the map needs a stable key that is unique among its siblings.
Why keys matter
React uses keys to match records across insertions, deletions, and reordering. Use a persistent record ID, not a random value generated during rendering. An index can work for a fixed list, but it can attach local state to the wrong item when the list changes. key is not passed to the child as a normal prop; pass the ID separately if the child needs it.
Follow the repository example
The street-food array becomes a set of image cards. Its key={index} is acceptable for this unchanging demonstration; use an ID or unique food name for an editable version. Keep an informative image alt and show a clear empty state when filtering yields no matches.
Recall check
Insert a new food at the beginning. Explain why stable keys preserve each card's identity even though its position changes.
Reference: Rendering lists and choosing keys.