Keep Typed Text with Its Row
Write the code, see it run, pass the checks.
The problem
- hard
- Code
- Pro
The Guests component gets a guests prop: a list of { id, name } objects (the preview uses Ada, Ben and Cleo with ids 1, 2 and 3). Show each guest as a list item holding a text input labelled "Note for Ada" (and so on) and a "Remove Ada" button. Above the list, a text input labelled "Guest name" and an "Add" button add a new guest at the top of the list with an id no other guest has, and empty the input; a blank name is ignored. A "Reverse order" button flips the list. Whatever is typed into a guest's note must stay with that guest when others are removed, added or the order is reversed. The starter uses each row's position as its key: see what goes wrong, then fix it.
Your code must pass
- Each guest has an empty note input
- Removing a guest keeps the other notes in place
- Reversing keeps each note with its guest
- A guest added at the top starts with an empty note