List Rendering Rendering Lists

Last updated: 2026-11-02

List Rendering Rendering Lists

React renders lists by mapping an array through map() into a set of JSX elements: prepare an array of data, return JSX with a unique key for every item, and you can render any collection as a list that updates automatically when the data changes. The key is what lets React match the new items with the old ones, so it is never optional.

GroupRendering & State
KindPattern
SinceEarliest React versions

ℹ️ Info The editor transpiles JSX to JavaScript and renders the real UI in a sandbox; components mount automatically — no manual render call needed.

📝 Syntax

<ul>
  {todos.map((todo) => (
    <li key={todo.id}>{todo.text}</li>  // map: array → array of JSX
  ))}
</ul>

Returns:No return value — a coding convention and mental model.

▶ Example

The example runs out of the box: it auto-renders when expanded, and edits take effect instantly.

Output:

The heading shows the number of tasks and the list below shows three todos; clicking "Add task" adds "Task 4", "Task 5" and so on in real time, and the count stays in sync.

💡 Key Points

⚠️ Warning Every element returned by map needs a stable, unique key, otherwise React warns in the console and updates can end up misaligned.
💡 Tip When the JSX of a list item gets complex, extract it into its own child component and keep the map body down to <TodoItem key={t.id} todo={t} />.
ℹ️ Info Besides map, methods that return new arrays such as filter and slice are often combined with list rendering.
More case studies coming soon.

📚 Related Tutorials

❓ FAQ

Q How do I render a list in React?
A Use the array's map method to turn every item into a JSX element with a key; the returned array of JSX renders as a list in order.
Q Why does a list rendered with map need keys?
A The key tells React the identity of each item, so the diff can tell what to add, move or delete; without it updates tend to misalign and performance suffers.
Q Where do I put the key when a list item is a component?
A On the outermost list element of the component call, <TodoItem key={t.id} />, not on the first element inside the component.
Web-Tutorial.com

Web-Tutorial Tech Team

A team of developers maintaining programming tutorials. Each tutorial is written and reviewed by developers with expertise in that field. We work to keep our content accurate and reliable — if you spot an issue, please let us know.

100%

🙏 帮我们做得更好

我们是刚上线的编程教程站,几个人的小团队,精力有限。页面虽经检查,难免还有疏漏——链接失效、排版错乱、内容有误、语言生硬……

如果您发现了,麻烦告诉我们,我们会在收到反馈后第一时间进行修复,再次感谢您的光临 🙏