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 Overflow
๐ŸŒ
React
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>

๐ŸŒ
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...
๐ŸŒ
Medium
thehumblecoder.medium.com โ€บ day-5-list-rendering-in-react-a4bdcda6629c
๐Ÿš€Day 5: List Rendering in React. Introduction | by Rahul Agarwal | Medium
February 28, 2025 - โœ… The importance of unique keys in React lists. โœ… How to apply basic styling to improve the UI. ... Stores a list of users in an array. Uses .map() to render the list dynamically.
๐ŸŒ
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 ...
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ reactjs โ€บ reactjs-lists
React Lists - GeeksforGeeks
August 7, 2025 - To render a list in React, we will use the JavaScript array map() function. We will iterate the array using map() and return the required element in the form of JSX to render the repetitive elements.
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ reactjs โ€บ list-all-ways-to-render-a-list-of-items-in-react
List all ways to render a list of items in React - GeeksforGeeks
July 23, 2025 - It leverages the map() method available on JavaScript arrays to iterate over each item and generate corresponding JSX elements. Each item in the array is transformed into a React component or element, facilitating the rendering process.
Find elsewhere
๐ŸŒ
LogRocket
blog.logrocket.com โ€บ home โ€บ rendering large lists in react: 5 methods with examples
Rendering large lists in React: 5 methods with examples - LogRocket Blog
June 4, 2024 - Explore five methods for easily rendering large lists in React, including pagination, infinite scroll, and several libraries.
๐ŸŒ
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.
๐ŸŒ
DEV Community
dev.to โ€บ tejeshwer25 โ€บ rendering-lists-in-react-55p4
Rendering Lists in React - DEV Community
September 6, 2021 - As we all know that ReactJS unlike ... to our web page. For rendering a list of items of our web app we can use the existing JavaScript map() method....
๐ŸŒ
Vegibit
vegibit.com โ€บ rendering-a-list-with-react
Rendering A List With React โ€“ vegibit
So in React, you can use the map() function to iterate over an array and create a list. Letโ€™s see how to do that now. Ok first things first. Before we even use any JavaScript arrays to help with creating a list, letโ€™s remind ourselves how ...
๐ŸŒ
DEV Community
dev.to โ€บ heatherhaylett โ€บ how-to-render-a-list-with-react-5988
How to Render a List with React - DEV Community
March 30, 2020 - If the format of an element can ... action, we use loops. To render a list in React we can use a higher-order function to iterate over data and display it on the page....
๐ŸŒ
CoreUI
coreui.io โ€บ answers โ€บ how-to-render-a-list-in-react
How to render a list in React ยท CoreUI
October 4, 2025 - Render lists in React using map() method with unique key props for dynamic content and efficient virtual DOM updates.
๐ŸŒ
freeCodeCamp
freecodecamp.org โ€บ news โ€บ how-to-render-lists-in-react
How to Render Lists in React using array.map()
April 10, 2023 - By Mwendwa Bundi Emma When you're working with React, you will often times need to render lists of items. With the map() method, you can create new results from your current lists or even showcase all the items in your lists. In this tutorial, ...
๐ŸŒ
Medium
medium.com โ€บ @stheodorejohn โ€บ list-rendering-in-react-a-comprehensive-guide-e46e6f58d11f
List Rendering in React: A Comprehensive Guide | by Theodore John.S | Medium
August 29, 2023 - In this article, weโ€™ll explore ... ... In React, list rendering refers to the process of dynamically generating UI components based on the items in an array or iterable....
๐ŸŒ
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
๐ŸŒ
DEV Community
dev.to โ€บ readwanmd โ€บ enhancing-react-list-rendering-a-clean-and-reusable-pattern-1d94
Enhancing React List Rendering: A Clean and Reusable Pattern - DEV Community
September 17, 2024 - Imagine you're building a dashboard for an e-commerce application. The dashboard includes several lists: recent orders, top-selling products, user comments, etc. You need to render each list using a .map() function.
๐ŸŒ
Medium
medium.com โ€บ @komalshehzadi โ€บ efficiently-rendering-lists-in-react-best-practices-and-pro-tips-a45651527ad9
Efficiently Rendering Lists in React: Best Practices and Pro Tips | by komal shehzadi | Medium
November 18, 2024 - Each rendered element must have a unique key prop. React uses the key prop to identify which items in a list have changed, been added, or removed.