You can do it in two ways:
First:
render() {
const data =[{"name":"test1"},{"name":"test2"}];
const listItems = data.map((d) => <li key={d.name}>{d.name}</li>);
return (
<div>
{listItems }
</div>
);
}
Second: Directly write the map function in the return
render() {
const data =[{"name":"test1"},{"name":"test2"}];
return (
<div>
{data.map(function(d, idx){
return (<li key={idx}>{d.name}</li>)
})}
</div>
);
}
Answer from Shubham Khatri on Stack OverflowReact
react.dev โบ learn โบ rendering-lists
Rendering Lists โ React
You will often need to show several instances of the same component using different data when building interfaces: from lists of comments to galleries of profile images. In these situations, you can store that data in JavaScript objects and arrays and use methods like map() and filter() to render lists of components from them.
Top answer 1 of 7
189
You can do it in two ways:
First:
render() {
const data =[{"name":"test1"},{"name":"test2"}];
const listItems = data.map((d) => <li key={d.name}>{d.name}</li>);
return (
<div>
{listItems }
</div>
);
}
Second: Directly write the map function in the return
render() {
const data =[{"name":"test1"},{"name":"test2"}];
return (
<div>
{data.map(function(d, idx){
return (<li key={idx}>{d.name}</li>)
})}
</div>
);
}
2 of 7
21
https://facebook.github.io/react/docs/jsx-in-depth.html#javascript-expressions
You can pass any JavaScript expression as children, by enclosing it within {}. For example, these expressions are equivalent:
<MyComponent>foo</MyComponent> <MyComponent>{'foo'}</MyComponent>This is often useful for rendering a list of JSX expressions of arbitrary length. For example, this renders an HTML list:
function Item(props) { return <li>{props.message}</li>; } function TodoList() { const todos = ['finish doc', 'submit pr', 'nag dan to review']; return ( <ul> {todos.map((message) => <Item key={message} message={message} />)} </ul> ); }
class First extends React.Component {
constructor(props) {
super(props);
this.state = {
data: [{name: 'bob'}, {name: 'chris'}],
};
}
render() {
return (
<ul>
{this.state.data.map(d => <li key={d.name}>{d.name}</li>)}
</ul>
);
}
}
ReactDOM.render(
<First />,
document.getElementById('root')
);
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.1.0/react.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.1.0/react-dom.min.js"></script>
<div id="root"></div>
Videos
07:16
React 19 Tutorial - 11 - Rendering Lists - YouTube
06:08
How to Render Lists Using map() in React | Display Arrays with ...
26:40
How to render LISTS in React ๐ - YouTube
08:47
Rendering a List of Components in React - YouTube
13:53
Render a list of task objects ReactJs | Best To Do List App #18.
11:57
ReactJS Tutorial - 17 - List Rendering - YouTube
Dave Ceddia
daveceddia.com โบ display-a-list-in-react
How to Display a List in React
The next time that component renders, React will say, โI already have some list items on screen โ are these ones different?โ It will avoid recreating DOM nodes if it can tell that the items are the same. But hereโs the important bit: React canโt tell with a simple equality check, because every time a JSX element is created, thatโs a brand new object, unequal to the old one. So thatโs where the key prop comes in...
React
legacy.reactjs.org โบ docs โบ lists-and-keys.html
Lists and Keys โ React
Usually you would render lists inside a component. We can refactor the previous example into a component that accepts an array of numbers and outputs a list of elements. function NumberList(props) { const numbers = props.numbers; const listItems ...
W3Schools
w3schools.com โบ react โบ react_lists.asp
React Lists - React Fundamentals
In React, you will render lists with some type of loop.
Amit Merchant
amitmerchant.com โบ effectively-rendering-lists-in-reactjs
Effectively rendering lists in React.js - Amit Merchant
April 27, 2022 - import { useMemo } from 'react'; export default function App() { const list = [ { key: 1, value: 10 }, { key: 2, value: 20 }, { key: 3, value: 30 } ]; const renderedList = useMemo(() => ( list.map(({ key, value }) => ( <div key={key}> {value} </div> )) ), [list]); return ( <div> {renderedList} </div> ); } As you can tell, we can offset the rendering logic to the useMemo() hook where we can pass in the list as its dependency.
GeeksforGeeks
geeksforgeeks.org โบ reactjs โบ different-ways-to-render-a-list-of-items-in-react
Different Ways To Render a List of Items in React - GeeksforGeeks
August 7, 2025 - Array.map() is a built-in JavaScript function provided by JavaScript. It iterates over the list of items in the array and returns a list of React components ยท map() function is called over the array, and a callback function is accepted as an argument ยท callback function will take the item and index as arguments