Free ATS Friendly Resume Builder Online

Create Your Resume

Resume Builder

Resume Maker

Resume Templates

Resume PDF Download

Create Your Resume is a free online resume builder that helps job seekers create professional, ATS friendly resumes in minutes. Easily build, customize, and download modern resume templates in PDF format.

Our resume maker is designed for freshers and experienced professionals looking to create job-ready resumes. Choose from multiple resume templates, customize sections, and generate ATS optimized resumes online for free.

Create resumes for IT jobs, software developers, freshers, experienced professionals, managers, and students. This free resume builder supports CV creation, resume PDF download, and online resume editing without signup.

Back to React Js
Lesson 16 of 59

How to Render Lists in React Using the map() Method

Rendering lists using the map() method is a common and powerful technique in React for displaying dynamic collections of data. React applications often work with arrays such as user lists, products, messages, or menu items. The map() method allows developers to transform an array of data into a list of React elements efficiently. When rendering lists, React also requires a unique key for each item to optimize rendering performance. Understanding how to use map() correctly is essential for building scalable, dynamic, and high-performance React user interfaces.

In React, applications frequently need to display multiple items based on data stored in arrays. Instead of manually creating UI elements for each item, React leverages JavaScript’s map() method to dynamically render lists. The map() method loops through an array and returns a new array, making it ideal for generating JSX elements.

At a basic level, map() takes a callback function and applies it to each item in an array. In React, this callback returns JSX instead of simple values.

Basic example of rendering a list:


function SkillList() {
  const skills = ["HTML", "CSS", "JavaScript", "React"];

  return (
    <ul>
      {skills.map(skill => (
        <li>{skill}</li>
      ))}
    </ul>
  );
}

This code dynamically creates a list item for each skill. However, this example is incomplete because React requires a unique key for each element in a list.

Importance of Keys in Lists

Keys help React identify which items have changed, been added, or removed. Without keys, React cannot efficiently update the UI, which may lead to performance issues or warnings.

Correct example using keys:


function SkillList() {
  const skills = ["HTML", "CSS", "JavaScript", "React"];

  return (
    <ul>
      {skills.map((skill, index) => (
        <li key={index}>{skill}</li>
      ))}
    </ul>
  );
}

While using the index as a key works in simple cases, it is not recommended for dynamic lists where items can be added, removed, or reordered. Instead, a unique and stable identifier should be used.

Better example with unique IDs:


function UserList() {
  const users = [
    { id: 1, name: "Akbar" },
    { id: 2, name: "Rahul" },
    { id: 3, name: "Sneha" }
  ];

  return (
    <ul>
      {users.map(user => (
        <li key={user.id}>{user.name}</li>
      ))}
    </ul>
  );
}

Rendering Components Using map()

The map() method is often used to render reusable components instead of plain HTML elements.

Example:


function User({ name }) {
  return <p>{name}</p>;
}

function UserList() {
  const users = ["Akbar", "Rahul", "Sneha"];

  return (
    <>
      {users.map(user => (
        <User key={user} name={user} />
      ))}
    </>
  );
}

This approach improves reusability and keeps components clean.

Conditional Rendering Inside map()

You can also apply conditions while rendering lists.

Example:


{users.map(user =>
  user.isActive ? <p key={user.id}>{user.name}</p> : null
)}

This is useful for filtering data directly in JSX.

Real-World Scenario

In real-world applications such as dashboards, e-commerce sites, or learning platforms, map() is used to render product lists, notifications, quiz questions, comments, or table rows. For example, a quiz app renders questions dynamically from an array, and each question is displayed using map() with a unique key.

Common Mistakes and Best Practices

Always provide a unique key for list items. Avoid using array indexes as keys for dynamic lists. Keep list-rendering logic simple and move complex transformations outside JSX. Ensure that map() always returns valid JSX elements.

In summary, rendering lists using the map() method is a fundamental React pattern for displaying dynamic data. Mastering map() and proper key usage is essential for building efficient, scalable, and maintainable React applications.