useField

useField is the primary hook for field components. Under the hood, it calls RHF's useController and merges the result with resolved field metadata — translated labels, visibility, disabled state, and validation rules — into a single flat object.

const { value, onChange, label, errorMessage, visible, ... } = useField()

The full list of returned props:

PropDescriptionNotes
valueCurrent field valueFrom RHF field.value
onChangeUpdate field valueFrom RHF field.onChange — accepts a plain value or a DOM event
onBlurMark field as touchedFrom RHF field.onBlur
refAttach to the input (anything with focus())From RHF field.ref — enables form.setFocus()
errorMessageReady-to-render error stringDerived from fieldState.error?.message — already translated, prefer over error
errorRaw RHF error objectFrom RHF fieldState.error — use only when branching on error.type
invalidtrue when field has a validation errorFrom RHF fieldState.invalid — shorthand for !!error
isDirtytrue after value changes from its defaultFrom RHF fieldState.isDirty
isTouchedtrue after onBlur is calledFrom RHF fieldState.isTouched
isValidatingtrue during async validationFrom RHF fieldState.isValidating
idDeprecated (removed in 1.0)The field's path, not unique on a page: not a DOM id. Use useId() in the adapter, or put the input inside its <label>
nameField key within its immediate scopee.g. "email", not "profile.email"
pathFull dot-notation pathe.g. "profile.email" — use with RHF APIs directly
namespaceParent section pathundefined for top-level fields
labelTranslated labelResolved from field config through i18n pipeline
descriptionTranslated helper textResolved from field config through i18n pipeline
requiredWhether field is requiredDerived from rules.required — do not infer this yourself
disabledWhether field is disabledResolved from field config and form state — excluded from submit payload
readOnlyWhether field is read-onlyResolved from field-level and form-level readOnly — still included in submit payload
visibleWhether the field is visibleAlways true in an adapter: a hidden field is not rendered
controllerRaw return value of RHF's useControllerAdvanced integrations only
configOriginal field config objectMeta-driven or dynamic fields only

Typing an adapter's props

A field component's props are what a config passes in props. When the component wraps a UI library input, take that input's props minus what useField() controls, with AdapterProps:

import type { TextInputProps } from '@mantine/core'
import { type AdapterProps, useField } from 'react-headless-form'

// the component's own props, minus value / onChange / label / disabled / … and Mantine's `error`
type TextFieldProps = AdapterProps<TextInputProps, 'error'>

function TextField(props: TextFieldProps) {
  const { value, onChange, onBlur, ref, label, errorMessage, disabled, readOnly } = useField()
  return (
    <TextInput {...props} ref={ref} label={label} value={value ?? ''} error={errorMessage}
      onChange={(e) => onChange(e.currentTarget.value)} onBlur={onBlur} disabled={disabled} readOnly={readOnly} />
  )
}

The config's props then autocompletes the library's props, and rejects the controlled ones: props: { value: 'x' } or props: { disabled: true } is a type error, since the adapter would override them (use the field's disabled / label keys instead). The second argument lists extra props the adapter sets itself (Mantine error, antd status, MUI inputRef).