Common pitfalls

A checklist of behaviors that are easy to get wrong. Each item links to the full explanation.

Setup

1. renderRoot is required. There is no default <form>. Provide it once in setupForm (or per <Form>), otherwise rendering throws.

const [Form] = setupForm({
  renderRoot: ({ children, onSubmit }) => <form onSubmit={onSubmit}>{children}</form>,
})

2. Install react-hook-form yourself. Since v0.14 it is a peer dependency: pnpm add react-headless-form react-hook-form. Hooks such as useFormContext / useWatch can then be imported from either package — they share the same context.

3. fieldMapping is fixed at setup time. It cannot be overridden per <Form>, so that field types and their props stay type-checked. Other setupForm options (renderRoot, i18nConfig, formOptions) can be overridden per form. A schema goes in the per-form schema prop (or a resolver in the per-form formOptions).

Values and validation

4. Validation runs on blur, then on change. BlueForm defaults to mode: "onTouched" and reValidateMode: "onChange" (RHF's default is onSubmit). An adapter that never calls onBlur is never touched, so its errors only appear after submit: call onBlur. Override with formOptions.mode.

5. Values start as undefined. Unless you pass defaultValues (form) or defaultValue (field), a field's value is undefined. Controlled inputs should render value ?? "" to avoid React's uncontrolled→controlled warning.

6. rules are ignored with a schema. With the schema prop or formOptions.resolver, every field-level rules entry is disabled (a console warning is logged). Pick one: rules or schema. The * marker comes from rules.required, so with a schema set required: true (or a condition) on the field. See Schema validation.

7. Hidden is not the same as not validated. A field hidden via visible keeps its registered value and rules unless it never mounted or shouldUnregister is on. For conditional requirements use rules.validate and a required function for the * marker. See Conditional rendering.

8. A field hidden from the first render never registers its defaultValue. Put initial values that must always be submitted in the form-level defaultValues.

Submit and change hooks

9. onSubmit errors go to onSubmitFailure, validation errors to onInvalid. The old onSubmitError only ever fired on validation errors (it is now a deprecated alias of onInvalid). Errors thrown by onSubmit are passed to onSubmitFailure — or logged — and never become unhandled rejections. See Form props.

10. Debounced changes are flushed on unmount. With debounceMs, the last pending onFieldChange / onFormChange call runs when the form unmounts; call ref.current.flushChanges() to run it earlier. Use useFormRef<TModel>() for a typed ref.

i18n

11. Only label, description, props.placeholder and error messages are translated. Other field props (title, aria-label, select options) are passed through untouched: translate them with your t where you build the config.

12. Every string label is treated as a translation key. Wrap text that is not a key (e.g. from a database) as { text: "..." } so t is skipped. See i18n.

Performance

13. visible / disabled / required functions only react to values read through their values argument. Since v0.16, BlueForm records those reads and re-runs a function only when they change (deps are inferred; deps is optional). A function that reads something else, such as getValues() from a closure or a mutable external store, is not re-run when that changes. Read form values from the argument, keep other state in React state (so the parent re-renders), or declare deps. See Conditional rendering → deps.

14. With shouldUnregister: true, React StrictMode can drop the values of array rows added with append(). StrictMode's simulated unmount / remount makes react-hook-form register the new row again from defaultValues, so its appended values are lost (development only). Keep shouldUnregister off for forms with arrays, or test that flow outside StrictMode.

15. append() focuses the new row by default. If that row has required fields, clicking "Add" again blurs it first: with mode: "onBlur" / "onTouched" its error appears, the layout shifts and the second click can miss the button. Pass append(row, { shouldFocus: false }) for repeated adds.