- Home
- /
- Tutorials
- /
- React Tutorial
- /
- Rendering Lists
Lists and Keys
Rendering Lists
Rendering a list is
map. There is no loop syntax in JSX because an array of elements is already something React knows how to render.
map returns elements
Because a JSX element is just a value, mapping an array of data to an array of elements is ordinary JavaScript. React renders each item in order.
Data to elements
jsx
function List() {
const people = [
{ id: 1, name: "Ada", role: "Engineer" },
{ id: 2, name: "Grace", role: "Admiral" },
{ id: 3, name: "Alan", role: "Logician" },
]
return (
<ul>
{people.map((person) => (
<li key={person.id}>
<strong>{person.name}</strong> — {person.role}
</li>
))}
</ul>
)
}
const root = ReactDOM.createRoot(document.getElementById("root"))
root.render(<List />)