Skip to content

toolmark-monorepo / @toolmark/react/rhf / rhfAdapter

Function: rhfAdapter() ​

rhfAdapter<V>(form, opts): FormAdapter<V>

Defined in: packages/react/src/rhf/index.ts:111

Bridges a react-hook-form useForm() instance to Toolmark form tools (spec §8.1, §9).

Reads form.formState.dirtyFields once, synchronously, when the adapter object is constructed: react-hook-form's formState is a Proxy that only tracks the fields it has been read for (dirtyFields included), so useFormTool (which builds the adapter during render, before any effect) enables this tracking even when the host component never reads formState itself.

Tour hooks (spec §13): onUserInteraction reports input for react-hook-form's own user-change signal (watch with type: 'change', never the adapter's setValue writes) and, when opts.root is given, focus for trusted focusin on named elements inside root() and submit for a trusted submit event inside it. Only paths are reported, never values.

  • input follows react-hook-form's own change signal, not the DOM event: a synthetic onChange from page script (or a component library calling field.onChange) is reported as a user input too. Only the DOM focus / submit reports check isTrusted.
  • Sensitivity (spec §14): with elements (root / elementFor), a path whose element was ever seen as a password / cc-* / secret-autocomplete input stays redacted for the adapter's lifetime, so a "show password" toggle (type="password" → "text") never exposes it in state(). A path is only known once its element has been seen that way; without root / elementFor nothing is detected, so declare secret paths in the form tool's sensitive.

Type Parameters ​

V ​

V extends FieldValues

Parameters ​

form ​

UseFormReturn<V>

The useForm() return value.

opts ​

RhfAdapterOptions<V>

See RhfAdapterOptions.

Returns ​

FormAdapter<V>