Keep React drafts with their list items
A real browser comparison of index keys and stable record IDs, plus the separate decision that determines whether a draft survives when its row disappears.

An editable list can look correct until someone changes its order. A reader adds a note to one item, sorts the list, and sees the note beside another title. Every card still looks polished; the relationship between the record and the draft is broken. For a frontend review, the useful question is simple: what should this unfinished text belong to when the interface moves?
Give a draft a record to belong to
Our study renders the same two records twice: “Atlas of paths” and “Field recordings.” Each row owns a small local state variable for its note. The first list uses the array index as its key. The second uses the record ID. We enter “Add a map” for Atlas in both lists, leaving Field blank. Before anything moves, the two versions appear equally convincing.
Before reversing the order. Actual Chromium capture at a 390 px viewport, cropped to the two list panels. The note starts with Atlas in both implementations.React uses keys to match siblings across changes in a list. Stable data IDs preserve that correspondence when items move. An index describes a place in the current array, so it is a poor identity for these reorderable records. Keys need to be unique among siblings and stable between renders; a freshly generated random key on every render defeats that purpose. Read React’s guidance on list keys.
Reverse the order before approving the component
We activate the same “Reverse order” button for both lists. Field moves to the first position and Atlas moves to the second. In the index-keyed list, “Add a map” now appears under Field. The first row’s local state stayed with key 0 while the record supplied to that row changed. In the ID-keyed list, the note remains with Atlas in its new position.
After the same keyboard-activated reorder, at the same 390 px viewport. Read the titles beside the filled inputs: the upper implementation misassigns the draft; the lower one preserves its record association.This is a particularly useful review case because a screenshot of the initial state hides the defect. Keep the note distinctive, make the order change obvious, and inspect both the record label and the input value. A test that merely checks whether “Add a map” is still somewhere on the page would accept the broken version.
Observed in the original fixture at 900 px and 390 px widths| Action | Index keys | Stable record IDs |
|---|
| Enter a note for Atlas | Note shown with Atlas | Note shown with Atlas |
| Reverse the two records | Note shown with Field | Note remains with Atlas |
| Remove Atlas, then restore it | No reliable record association | Atlas returns with an empty local note |
All six browser-and-viewport checks reproduced the reorder result: Chromium 153.0.8010.12, Firefox 155.0 and WebKit 26.6, each at the two widths above. The fixture uses React and React DOM 18.3.1 from this workspace. These are the tested builds, not a claim about the newest releases or a speed comparison. The source, captures and assertions were retained with the article.
Put the identity on the mapped component
The key belongs on the row returned directly by map. Pass the record separately so the row can render its title and input label. Here is a compact version of the stable-ID pattern used in the study. The NoteRow definition stays outside ReadingList; each row begins with an empty string and updates its controlled input as the reader types. See React’s controlled-input reference.
import { useState } from 'react';
function NoteRow({ item }) {
const [note, setNote] = useState('');
return (
<li>
<h3>{item.title}</h3>
<label>
Draft note for {item.title}
<input value={note}
onChange={e => setNote(e.target.value)} />
</label>
</li>
);
}
function ReadingList({ items }) {
return (
<ul>
{items.map(item => (
<NoteRow key={item.id} item={item} />
))}
</ul>
);
}
For a build handoff, include a small record sample with persistent IDs and a repeatable interaction sequence. “Keep the note for atlas when the list reverses” is a clearer acceptance condition than “use good React keys.” If a coding agent produces the component, run the interaction against the result instead of accepting the presence of a key prop as sufficient evidence.
Separate identity from draft storage
The second experiment removes Atlas from the rendered list and then restores it. Its stable key has not changed, but its note is empty. Removing a component discards its local state. A key helps identify a mounted sibling; it is not a draft database. React’s state guide describes keeping important drafts in a parent when a child needs to disappear. Read the state-preservation explanation.
Choose how long the draft should live
While the row stays mounted
Local row state with a stable record key fits a simple reorderable list.
- The tested reorder keeps the note with its record.
- Removing the row ends that local state.
- Define whether discarding the note is acceptable.
While records come and go
For a filterable editor, consider keeping drafts in a longer-lived parent, indexed by record ID.
- Write down the restore behavior before implementing it.
- Decide when a draft is saved, discarded or intentionally reset.
- Reload survival needs a separate persistence design; this fixture does not implement it.
That distinction changes the review conversation. A temporary filter may be expected to preserve work, while deleting a record may be intended to discard it. Treat those as separate product actions even if both remove a row from view. The next implementation should make the chosen behavior observable, including a clear way to recover or intentionally clear a draft.
Review an editable list in four passes
Name the owner
Write a distinctive note and identify its record by a stable ID. Check the visible label and the value together.
Change the arrangement
Reverse, sort and insert records before the edited row. Confirm the note stays with its intended record, not merely somewhere in the list.
Remove and return
Try filtering and restoring the edited record. Compare the result with the agreed draft-retention behavior.
Check the actual interaction
Use the controls with a keyboard at narrow and wide widths. Review labels, focus visibility and intentional reset behavior alongside state ownership.
The smallest useful proof is a pair of states: the same identified record before and after a meaningful list change. Keep that proof beside the implementation. It gives designers, engineers and coding agents a shared way to judge whether the interface has preserved the reader’s work.
Back to the LOOKFILE blog