Build reusable inputs that consume their own Conform field metadata.
Design-system controls
Conform · Hook
useField is a React hook that reads field metadata from a FormProvider. It supports reusable field components and can target a specific form with formId.
useField is a React hook from Conform's future export that reads field metadata inside a FormProvider. It uses the nearest form context by default, or a specified formId, and returns generated identifiers, naming information, default value, accessibility state, and schema-derived HTML validation attributes.
const field = useField(name, options);| Name | Type | Description |
|---|---|---|
name | FieldName<FieldShape> | The input field name or field-name path. |
options | { formId?: string } | Optional configuration. Its documented property is formId, used to select a specific form context. |
A Field object containing field metadata and state, including id, name, formId, descriptionId, defaultValue, aria-invalid, aria-describedby, and schema-derived HTML validation attributes.
import { FormProvider, useField } from '@conform-to/react/future';
function TextField({ name }: { name: string }) {
const field = useField(name);
return (
<div>
<label htmlFor={field.id}>{name}</label>
<input
id={field.id}
name={field.name}
form={field.formId}
defaultValue={field.defaultValue}
aria-invalid={field['aria-invalid']}
aria-describedby={field['aria-describedby']}
/>
</div>
);
}
export function Example() {
return (
<FormProvider context={context}>
<TextField name="email" />
</FormProvider>
);
}A reusable field component reads its metadata from the nearest FormProvider and applies the generated identifiers and validation attributes to an input.
Design-system controls
Nested forms
Accessible validation UI
Schema-driven browser constraints
useField reads field metadata from a FormProvider and is intended for reusable field components that avoid prop drilling. It returns metadata such as the field id, name, form id, default value, accessibility attributes, and validation attributes.
Follow-up: How can a field target a non-nearest form? Pass options.formId so the hook selects the intended form context.
The name argument identifies the field. The optional options object currently supports formId, which targets a particular form when multiple or nested form contexts exist.
Follow-up: What happens when formId is omitted? The hook uses the nearest form context.
The hook provides generated identifiers and accessibility state for wiring controls to their form and descriptions. It also exposes schema-derived constraints such as required, minLength, maxLength, pattern, min, max, and step when applicable.
Follow-up: Why are these useful? They let reusable controls apply consistent browser validation and accessibility metadata without manually reconstructing field state.
FormProvideruseFormuseFormMetadataFieldNamegetField