Form Input Values Resetting
What you'll learn: Why uncontrolled form inputs mysteriously lose their typed values when list keys change, even though the data itself is still there.
The Problem: Vanishing Input Values
You've seen how keys tell React which component instance is which. But there's a subtle, frustrating consequence with uncontrolled form inputs specifically: when you change a key, React destroys the old DOM node and creates a brand new one. The input's value? Gone.
Remember, uncontrolled inputs store their values in the DOM itself, not in React state. When React sees a different key, it doesn't just update the component—it literally removes the old <input> element from the page and mounts a fresh one. Your typed text never made it to React's memory, so there's nothing to restore.
Why This Happens
// Before: user typed "Hello" in the input (stored in DOM)
<input key="item-5" defaultValue="" />
// After: key changes (maybe you sorted the list)
<input key="item-5-sorted" defaultValue="" />
// React destroys the old DOM node entirely
// The new input starts fresh with empty value
The defaultValue prop only sets the initial value. Once the input is mounted, subsequent typing updates the DOM directly—and that state lives outside React's control.
The Fix
Use controlled inputs (value + onChange) so React owns the state, or ensure your keys remain absolutely stable. If keys never change, React preserves the same DOM node, and the input's internal state survives.
Key Takeaway: Uncontrolled form inputs lose their typed values when keys change because React destroys and recreates the DOM node, wiping out any user input stored there. Controlled inputs don't suffer this issue because their values live in React state.