Modern web applications are built around collections of data: lists of products, feeds of social posts, tables of transactions, or directories of courses. In React, you don't write manual for loops to insert DOM elements. Instead, you use JavaScript's functional Array.prototype.map() method to transform an array of data objects into an array of JSX elements.
Here is a straightforward example rendering an array of strings:
In enterprise applications, data almost always arrives from APIs as an array of objects. You can map over these objects and extract their properties cleanly:
When each list item contains complex markup, multiple event handlers, or local state, inline JSX inside .map() can become difficult to read and maintain.
The industry standard pattern is to extract the item into its own dedicated component:
Note: The key prop must always be placed directly on the element or component returned inside the .map() callback (here, on <CourseCard key={course.id} />), not inside the child component.
forEach() NOT used directly inside JSX curly braces to render a list?key prop be placed when mapping an array to a custom child component?[] to .map() in React JSX?Continue learning with hands-on practice, examples, and exercises in the upcoming topic.
| Previous Lesson | Next Lesson |
|---|---|
| Preventing Default Browser Behaviors | The Critical Importance of Unique Keys |
Test your understanding of this lesson with 5 questions. Each question has one correct answer.
Practice in live mentor-led sessions with real projects, mock tests, and verifiable certification at MSK Institute.