How to use map() to Create Lists in ReactJS ? Last Updated : 10 Oct, 2024 Comments Improve Suggest changes Like Article Like Report 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 lists in React using the map function we will use useState to store the data as an array. Iterate this array using map and transform each item to a react component. Render it as a list on the UI by enclosing it with a parent div.Creating React ApplicationStep 1: Create a React application using the following command:npx create-react-app listmapdemoStep 2: After creating your project folder i.e. listmapdemo, move to it using the following command:cd listmapdemoProject Structure:It will look like the following.Project StructureExample: This example uses the map function to render a lsit of fruits items stored as an array. The index of array item is used as the key in the final list. JavaScript // Filename - App.js import React from "react"; function App() { // Declared an array of items const fruits = ["Apple", "Mango", "Banana", "GFG"]; // Some styling for the items const styles = { backgroundColor: "white", width: "50px", marginBottom: "10px", padding: "10px", color: "green", boxShadow: "rgb(0,0,0,0.44) 0px 5px 5px", }; return ( <> { /* This maps each array item to a div adds the style declared above and return it */ fruits.map((fruit) => ( <div key={fruit} style={styles}> {fruit} </div> )) } </> ); } export default App; Step to Run Application: Run the application using the following command from the root directory of the project:npm startOutput: Now open your browser and go to http://localhost:3000/, you will see the following output: Comment More infoAdvertise with us Next Article How to use map() to Create Lists in ReactJS ? ganesh227 Follow Improve Article Tags : Web Technologies ReactJS React-Questions Similar Reads 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 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 How To Create a Website in ReactJS? ReactJS is one of the most popular JavaScript libraries for building user interfaces. It allows you to create dynamic, reusable UI components and efficiently manage state and events. In this article, we'll walk through the steps to create a basic website using ReactJS.PrerequisitesNPM & Node.jsR 5 min read How to create a table in ReactJS ? In ReactJS, tables are commonly used to display data in rows and columns. Tables can be static, where data is hardcoded, or dynamic, where data is passed from an array or fetched from an API. React makes it simple to create interactive and dynamic tables, with additional features such as sorting, pa 6 min read How to Map Data into Components using ReactJS? Mapping data in react js component is a comman practice to render the lists and repeating elements. In this article, we will have a users data and we will map it to react components to display the users information in the react appPrerequisites:React JSNodejs and npmJavaScript Array mapApproachTo ma 3 min read How to use GridList in ReactJS? Grid lists display a collection of images in an organized grid. Material UI for React has this component available for us and it is very easy to integrate. We can use the GridList component in ReactJS using the following approach. Creating React Application And Installing Module: Step 1: Create a Re 2 min read How To Use Checkboxes in ReactJS? Checkboxes are essential UI components used in web applications that allow users to select one or more options from a list. React makes it simple to work with checkboxes, whether you're dealing with a single checkbox or a list of checkboxes. In this article, we will see how to use Checkboxes in Reac 2 min read How to create SpreadSheet in ReactJS ? In this article, we are going to learn how we can create SpreadSheet in ReactJs. A spreadsheet is a file that exists of cells in rows and columns and can help arrange, calculate and sort data.React is a free and open-source front-end JavaScript library for building user interfaces or UI components. 2 min read How to Convert CSV to JSON in ReactJS ? Dealing with data in various formats is a common task in web development. CSV (Comma Separated Values) and JSON (JavaScript Object Notation) are two widely used formats for storing and transmitting data. Converting CSV to JSON is often required when working with data in ReactJS applications. Approac 4 min read How to Create Store in React Redux ? React Redux is a JavaScript library that is used to create and maintain state in React Applications efficiently. Here React Redux solves the problem by creating a redux store that stores the state and provides methods to use the state inside any component directly or to manipulate the state in a def 4 min read Like