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>
);
}
β¨ 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)