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>
Using anything rather than .map to render lists in JSX?
I've used for loops cos state held an array, even experimented with reduce to create a single consolidated code block of lists, but nothing else is as simple and effective as using map. More on reddit.com
How to re-render a map loop in React?
It looks like there's two problems: You're mutating the existing data array by calling Array.splice() It also doesn't look like that data array is in React state, and you're not calling any form of setState(). React requires that you call some form of setState() to cause a re-render. I'd recommend going through the React beta docs to understand how to use state in components and update it: https://beta.reactjs.org/learn/state-a-components-memory https://beta.reactjs.org/learn/updating-arrays-in-state You might also want to read my post A (Mostly) Complete Guide to React Rendering Behavior to better understand how React rendering works. More on reddit.com
How do you render bullet points in react.js? Which syntax should I use? Which blogs and tutorials teaches me how to render bullet points in React.js?
Render a list? I'm not sure if there's more to this question. Assuming you're using JSX you be able to just make your render function... render() { return (
- Coffee
- Tea
- Milk
How to Render a List of Objects in React ?
Good video. What if I want to render the data such that each list object renders in a simple box that contains the object data rather than a bullet point list?
More on reddit.comVideos
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...
W3Schools
w3schools.com › react › react_lists.asp
React Lists - React Fundamentals
In React, you will render lists with some type of loop.
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 ...
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
Uber
uber.com › us › en › blog › supercharge-the-way-you-render-large-lists-in-react
Supercharge the Way You Render Large Lists in React
December 21, 2023 - Here’s the implementation of the same 10,000-item list using react-infinite-scroller. ... Our total performance scroll jumped from a base of 43 to 78, which is a massive gain. This is because of the fact that we essentially chopped our list into tiny portions. Instead of rendering all 10,000 items at once, we only rendered the first few items needed to render the portion of the page in the user’s view.