DEV Community

Aman Kureshi
Aman Kureshi

Posted on

πŸ—ΊοΈ Rendering Lists in React Using map()

In React, you often need to display a list of items. The map() method makes this easy.

πŸ“˜ Example:

const fruits = ["Apple", "Banana", "Orange"];

function FruitList() {
  return (
    <ul>
      {fruits.map((fruit) => (
        <li key={fruit}>{fruit}</li>
      ))}
    </ul>
  );
}
Enter fullscreen mode Exit fullscreen mode

✨ Key Points:
β€’ map() transforms data into UI elements
β€’ Always provide a unique key
β€’ Keeps your code clean and dynamic

map() is one of the most commonly used patterns in React.

Top comments (0)