How to Render Lists in React? Last Updated : 19 Mar, 2024 Comments Improve Suggest changes Like Article Like Report In React, rendering lists of data is a common task. There are multiple approaches to achieve this. In this article we will explore various approaches to render lists in React. Table of Content Using map() methodUsing forEach() methodSteps to Setup a React App:Step 1: Create a React application using the following command. npx create-react-app myappStep 2: Navigate to the project directory cd myappProject Structure: Approach 1: Using map() methodThis approach uses map() method which is used to iterate over an array and transform each element into a new array of React elements. It is used in React to render lists of elements, as it allows us to easily generate JSX for each item in the array. Syntax of map() method:Array.map((currentValue, index)=>(// method body))Example: Below example describes how we can use map method to render lists of data. JavaScript // page.js import React from "react"; const languages = [ { name: "JavaScript", founder: "Brendan Eich" }, { name: "Python", founder: "Guido van Rossum" }, { name: "Java", founder: "James Gosling" }, { name: "C++", founder: "Bjarne Stroustrup" }, { name: "Ruby", founder: "Yukihiro Matsumoto" }, ]; function LanguageList() { return ( <div style={{ textAlign: "center" }}> <h1 style={{ color: "green" }}>GeeksForGeeks</h1> <h2 style={{ textAlign: "center", marginBottom: "20px" }}> Rendering List using map method </h2> <ul style={{ listStyleType: "none", padding: 0 }}> {languages.map((language, index) => ( <li key={index} style={{ marginBottom: "10px", padding: "10px", backgroundColor: "#f4f4f4", borderRadius: "5px", }} > <strong>{language.name}</strong> - Founder:{" "} {language.founder} </li> ))} </ul> </div> ); } export default LanguageList; Output: Approach 2: Using forEach() methodThis approach uses forEach method which is be used to iterate over an array of items and perform side effects, such as rendering JSX elements for each item. Example: Below is an example of how we can use forEach to render a list of items JavaScript // page.js import React from "react"; const languages = ["JavaScript", "Python", "Java", "C++", "Ruby"]; const listItems = []; languages.forEach((language, index) => { listItems.push(<li key={index}>{language}</li>); }); function LanguageList() { return ( <div style={{ textAlign: "center" }}> <h1 style={{ color: "green" }}>GeeksForGeeks</h1> <h2 style={{ textAlign: "center", marginBottom: "20px" }}> Rendering List using forEach method </h2> <ul style={{ listStyleType: "none", padding: 0 }}> {listItems} </ul> </div> ); } export default LanguageList; Output: Comment More infoAdvertise with us Next Article How to Render Lists in React? yuvrajghule281 Follow Improve Article Tags : Web Technologies ReactJS React-Questions Similar Reads How To Render An Array Of Objects In ReactJS? Rendering dynamic data in ReactJS is one of the most fundamental tasks when building interactive web applications. One of the most common scenarios is rendering an array of objects, such as a list of users, products, or posts, in the user interface (UI). To render an array of objects in React we wil 4 min read How to Create List Styling in ReactJS ? React, a declarative, efficient, and flexible JavaScript library for building user interfaces, plays a crucial role as the 'V' in MVC. Specifically, ReactJS, an open-source, component-based front-end library maintained by Facebook, focuses on the view layer of applications. In this article, we will 3 min read List all ways to render a list of items in React In React applications, rendering lists of items is a fundamental task. You will often need to display collections of data, such as product listings, to-do items, or user comments. There is well-established approach that combines JavaScript's array methods and React's component structure to achieve t 5 min read How to use map() to Create Lists in ReactJS ? The map function is generally used to render the list items dynamically in react. This function iterates over the array and each iteration returns the JSX for respective item. It helps to render and display the list efficiently. Prerequisites:React JSJavaScript Array.mapApproachTo create and render 2 min read How to use List Component in ReactJS? Lists are continuous, vertical indexes of text or images. Material UI for React has this component available for us, and it is very easy to integrate. We can use the List Component in ReactJS using the following approach. Prerequisites:NodeJS or NPMReactJSSteps to Create the React Application And In 2 min read Different Ways To Render a List of Items in React In React, when we are working with dynamic data, it is common to render a list of items. In React, there are several methods to render the list efficiently.1. Using Array.map()Array.map() is an inbuilt JavaScript function provided by JavaScript. It iterates over the list of items in the array and re 5 min read How to use styles in ReactJS ? React is a popular JavaScript library for building single-page applications (SPAs) with dynamic user interfaces. Styling in React can be done in various ways, each with its advantages. In this article, we will explore different approaches to applying styles in React, including inline styles, CSS fil 4 min read How to reorder list of items using Framer Motion in ReactJS? To reorder the list of items using Framer Motion in ReactJS we will use a dummy list and the reorder component that enables reordering of items on user interaction.Prerequisites:NPM & Node.jsReactJSIntroduction of Framer-motionApproachWe can reorder a list of items using the Framer motion librar 2 min read ReactJS Rendering Elements In this article we will learn about rendering elements in ReactJS, updating the rendered elements and will also discuss about how efficiently the elements are rendered.What are React Elements?React elements are different from DOM elements as React elements are simple JavaScript objects and are effic 3 min read Explain the purpose of render() in ReactJS Render in React JS is a fundamental part of class components. It is used to display the component on the UI returned as HTML or JSX components. The ReactDOM.render() function takes two arguments, HTML code and an HTML element.Purpose of render()React renders HTML to the web page by using a function 2 min read Like