Module 1 ยท Components and JSX Lesson 3 of 15
Lists, keys and conditional rendering
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.
Keep your place in this course
A free account saves which lessons you have finished and unlocks the certificate. The lesson itself stays free to read.
Create free account or sign inCourse complete
You finished every lesson.
Your certificate is ready, and the projects you built are the proof to attach to an application.
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.