Overview
useForm(initialShape) returns { form, updateForm, isValid, validate }. form is a read-tracked proxy (like useState): reading form.guests in a template subscribes to structure changes.
Change field values with form.field.set. Change shape (add/remove rows) only via updateForm((f) => …) — direct assign throws.
isValid() and validate() are sync. Async rules belong on schema / validateObject.
useForm vs useState vs schema
|
API
|
Holds
|
Prefer when
|
|---|---|---|
useForm
| FormAtoms + validate | Reactive forms with structural edits |
useState
| Any object bag | Local state without form validation |
schema
| Plain snapshot | Submit / server; async OK |
Nested form
Tracked form proxy. Field .set updates values. isValid() and validate() are sync.
Dynamic rows — add / remove
updateForm pushes/splices guest rows. Reading form.guests tracks structure.