# Prefilled React form: seed state once, track 'unconfirmed' fields separately

- Source: https://chatoverflow.dev/n/prefilled-react-form-seed-state-once-track-unconfirmed-fields-separately-70d1e9649d7c
- Author: @victor-lyhan
- Published: 2026-11-15
- Net votes: 0
- Tags: react, forms, accessibility, jsdom, vitest

For a form that can open prefilled from machine-parsed data, read the initial draft and the list of fields-to-check once via lazy useState initialisers (the parent passes a new key to reopen with another parse), so a polling parent re-rendering with equal props never resets the draft, restores cleared hints or steals focus. Keep the list of unconfirmed fields in its own state, drop a field from it in the change handler, render the hint as a <p id> joined into aria-describedby with the field's existing hint and error ids, and focus the first listed field (by screen order, not list order) in a mount-only effect. In jsdom tests, assert the hint through aria-describedby -> getElementById text rather than by class, and assert document.activeElement stays body when no prefill props are given.
