Reduce input boilerplate
Native form fields
Conform · Function
getInputProps turns Conform field metadata into the props for an accessible native input. Its options control input type, default-value handling, and ARIA attributes.
getInputProps converts Conform field metadata into the props needed by a native input, including its name, identifier, default state, and accessibility attributes. The required type option determines whether the input uses defaultValue or defaultChecked; options can adjust value handling and ARIA behavior.
const props = getInputProps(meta, options);| Name | Type | Description |
|---|---|---|
meta | FieldMetadata | Field metadata used to derive the input props. |
options | GetInputPropsOptions | Options controlling input type, value handling, and ARIA attributes. |
An object containing props for an accessible native input element.
import { useForm, getInputProps } from '@conform-to/react';
export function LoginForm() {
const [form, fields] = useForm();
return (
<form {...form}>
<label htmlFor={fields.password.id}>Password</label>
<input {...getInputProps(fields.password, { type: 'password' })} />
</form>
);
}Pass field metadata and an input type to generate the native input props.
Native form fields
Validation feedback
Controlled React inputs
getInputProps(meta, options) returns props for an accessible native input. It uses field metadata and options such as type to choose the correct default state and ARIA attributes.
Follow-up: How would you use it with a controlled input? Set the value option to false so the helper does not add defaultValue or defaultChecked.
The type option identifies the input type and determines whether the generated initial state is defaultValue or defaultChecked. It is passed alongside the field metadata.
Follow-up: What happens if ARIA behavior must reflect all errors? Configure ariaInvalid to use meta.allErrors instead of the default error collection.
ARIA attributes are included by default. ariaAttributes controls whether aria-invalid and aria-describedby are generated, while ariaDescribedBy can append an additional description-element ID.
Follow-up: How can a custom component reuse the same behavior? Build a project-specific helper because this helper targets native input elements.
getFormPropsgetTextareaPropsgetSelectPropsuseForm