Map Function Usage in React
📖 Scenario: You are building a simple React component that shows a list of fruits on a webpage. Each fruit name should appear as a separate item in a list.
🎯 Goal: Create a React functional component that uses the map function to display each fruit from an array as a list item inside an unordered list.
📋 What You'll Learn
Create an array of fruits with exact values: 'Apple', 'Banana', 'Cherry', 'Date', 'Elderberry'.
Create a variable called
fruitList that uses map to convert each fruit into a <li> element with a unique key.Render the
fruitList inside a <ul> element in the component return.Use a functional component named
FruitList.💡 Why This Matters
🌍 Real World
Displaying lists of items dynamically is common in web apps, such as showing products, messages, or user profiles.
💼 Career
Understanding how to use map in React to render lists is a fundamental skill for frontend developers working with React.
Progress0 / 4 steps