How to create new elements with React JS mapping props ? Last Updated : 25 Jul, 2024 Summarize Comments Improve Suggest changes Share Like Article Like Report We'll learn how to create new elements in React JS using the map() function and props. It's suitable for both beginners and those looking to improve their React skills. The tutorial offers a step-by-step walkthrough, helping you create adaptable and reusable components by effectively using props and the map() function.Prerequisites:Node JS or NPMReact JSMap()Following is the example of the map method:// Sample arrayconst array1 = [1, 4, 9, 16];// Pass a function to mapconst map1 = array1.map(x => x * 2);console.log(map1);// Expected output: Array [2, 8, 18, 32]Steps to create React Application And Installing Module:Step 1: Create a React application using the following command:npx create-react-app foldernameStep 2: After creating your project folder i.e. foldername, move to it using the following command:cd foldernameProject Structure:The updated dependencies in package.json file will look like:"dependencies": { "react": "^18.2.0", "react-dom": "^18.2.0", "react-scripts": "5.0.1", "web-vitals": "^2.1.4",}Example: Now write down the following code in the App.js file. JavaScript import React from "react"; class App extends React.Component { getComponent = (arr) => { return arr.map((value) => ( <button key={value} onClick={() => { alert("button " + value + " is clicked"); }} > {value}{" "} </button> )); }; render() { const components = this.getComponent([1, 2, 3, 4, 5]); return <div>{components}</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 Comment More infoAdvertise with us Next Article How to change the position of the element dynamically in ReactJS ? K KapilChhipa Follow Improve Article Tags : Web Technologies ReactJS React-Questions Similar Reads How to Create More Options in ReactJS ? More Options in React JS is a common feature that every application has to show the user some extra functionality on clicking on that button. Material UI for React has this component available for us and it is very easy to integrate. Prerequisites:NPM & Node.jsReact JSReact Material UIApproach:T 2 min read What is the use of React.createElement ? React.createElement is a fundamental method of React JS. The main use of React.createElement is the Creation of a React component. It is the JavaScript format for creating react components. Also, the JSX react component when transpired invokes this only method for creating the component. Syntax:Reac 2 min read How to Pass Padding/Margin as Props in React-Bootstrap Components? In React-Bootstrap there are many components through which we can design our application. To style the application, we need to specify the padding and margin for these components. So, we can pass this custom padding and margin as props in these components. We can make our own custom components that 5 min read How to change the position of the element dynamically in ReactJS ? To change the position of an element dynamically based on certain conditions or user interactions, we can access and modify its styling and link to certain events. When these events trigger that in return will change the position of the elementPrerequisitesReact JSNPM and Node.jsReact JS Class Compo 2 min read How to access a DOM element in React ? React manages the rendering of components and updates the DOM automatically. However, there are situations where you may need to access a specific DOM element directly. We will use the Refs to access a DOM element in React. Refs provide a way to access DOM nodes or React elements created in the rend 3 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 Like