๐Ÿ“Š We use cookies & analytics to improve your experience. Learn more
Latest

React & Modern Front-End Development Module 1 ยท Lesson 3 of 15

0% Exit to course

Module 1 ยท Components and JSX Lesson 3 of 15

Lists, keys and conditional rendering

Learning objective

Rendering a list means mapping an array to components, and React needs a stable key to know which row changed. An index as a key is the classic bug that only shows up when the list reorders.

Worked example

items.map((it) => <Row key={it.id} item={it} />) is correct. key={index} looks identical on screen and produces the wrong row updating once you sort or delete โ€” exactly the defect you do not want to explain in an interview.

Your practice task

Render a list of twenty items, add a delete button on each row, and fix the keys so deleting the second row deletes the second row.

Do this before moving on. Reading a solution teaches the shape of it; typing it teaches you.

Key takeaway

Rendering a list means mapping an array to components, and React needs a stable key to know which row changed. An index as a key is the classic bug that only shows up when the list reorders.

Create free account or sign in

Almost there

15 lessons left of 15

Finish every lesson to unlock the certificate. Each one ends in a practice task โ€” do them and the final project brief writes itself.

Next recommended course Full-Stack Web Development Bootcamp