Lesson 7 of 15
Generating UI from Data (Rendering Lists)
Lesson Updated: Apr 28, 2026
Requirement
Understand how to take raw data (like an array of user names) and automatically turn it into an array of UI components. Instead of copy-pasting code 10 times for 10 users, you write the component layout once and tell React to loop over the data and generate the UI for you.
Assignments (Start First)
- Simple beginner UI task: Create an array of your favorite movies (just strings). Build a
MovieListcomponent that uses JavaScript's.map()method to render an unstyled<ul>containing an<li>for each movie. - Slightly improved version: Change your data to be an array of objects (e.g.,
{ id: 1, title: "Inception" }). Render the list again, but this time ensure you pass the uniqueidas a specialkeyprop to the<li>element to clear the React console warning. - Practical real-world component: Build a
NavigationSidebar. Take an array of route objects (e.g.,{ label: "Home", icon: "🏠", isActive: true }) and map them into a stylized sidebar menu. If an itemisActive, give it a distinct highlighted background color. - "The Escalation": Create a
TaskManager. Start with an array of task objects in state. Map over the state array to render a list of beautifully styledTaskCardcomponents. Add a "Delete" button inside each card that, when clicked, filters that specific task out of the state array, causing the list to update instantly.
Lessons (Optional)
- The .map() Method: The standard JavaScript array method. In React, we use it to transform an array of data into an array of JSX elements.
- Keys: Every time you render a list in React, the outermost element in the loop MUST have a unique
keyprop (usually a database ID). - Data Separation: Keeping your raw data structured in arrays/objects keeps your JSX clean and readable.
The Summary and Quizzes
- Concept explanation: Rendering lists allows us to build scalable, flexible UIs that grow automatically as our data grows, without duplicating code.
- Why it works in React: React loops through your array and stamps out a component for every item. It uses the
keyprop to track each specific item, so if one item gets deleted or changed, React only updates that one piece instead of destroying and redrawing the whole list. - Challenge question: Why is it considered a bad practice to use the array
indexas akeyprop if the user is allowed to delete or reorder items in that list?