DEV Community

Sherotree
Sherotree

Posted on

Give the agent the existing form-library pattern, don’t invent a new useState form

The agent adds an “edit display name” form with four useState hooks, a hand-rolled errors object, and a disabled={loading} flag that does not match the existing submit button. The repo already uses React Hook Form (or Formik, or the design-system useForm) with a shared validation helper and a standard error message component. The new form ignores all of it, so the field chrome, the error announcement, and the submit policy look different from every other settings row.

I’ve started treating a from-scratch useState form in a repo that already has a form library as a rewrite, not as a small UI addition. The library is there so validation, touched state, and submit errors stay consistent.

Why the hand-rolled form shows up

Tutorials start with useState. The model can generate that without opening another file. Wired-up RHF examples take more context: the resolver, the field component, the way the app shows aria-invalid. If you do not paste a nearby form, the agent will invent a simpler one.

The hidden cost is accessibility and consistency. A custom error <span> often is not tied to the input. A custom onSubmit may not prevent double submits the way the shared hook does. Reviewers then have to re-teach the house style on every form PR.

A simple form policy

  • Copy a nearby form of the same kind (settings row, modal, wizard step)
  • Use the existing form library and field components
  • Reuse the shared validator and error component
  • Do not add a second form library, and do not mix useState field state with library state in the same form

If the change is one checkbox on an existing form, extend that form. Do not start a parallel mini-form beside it.

What to put in the prompt

This repo uses React Hook Form (see src/components/forms/SettingsRow.tsx and src/lib/form.ts).
Build this form the same way: useForm, the shared Field component, and the shared error message.
Do not introduce a new useState-per-field form, and do not add Formik or another library.
Client validation should reuse the existing helper. Do not invent a new errors object.
Enter fullscreen mode Exit fullscreen mode

Paste one real form, not a generic snippet from memory. In review, search the diff for useState( next to input handlers, and for a second form library in package.json.

Reject / send back

Reject

  • A new form built from useState and onChange in a RHF/Formik codebase
  • A second form library added “just for this modal”
  • Custom error text that is not hooked to the input
  • A parallel form beside an existing one that already has the field

Accept

  • A new form that copies the existing pattern and components
  • A single extra field on the form that already owns the resource
  • A genuine uncontrolled native form in a non-SPA surface the library does not cover, called out in the PR

Top comments (0)