Render nested object fields
A schema contains an object such as an address with street, city, and postal-code fields.
Conform · Pipe
getFieldset() returns the child-field metadata for a nested object. Call it on the parent field metadata to access nested fields with names inferred automatically.
Call getFieldset() on a field's metadata when that field represents a nested object. The returned fieldset exposes each child field as a property, and Conform infers the child names from the parent path, avoiding manually constructed names.
field.getFieldset()A fieldset object containing the nested field metadata as properties.
import { useForm } from '@conform-to/react';
export function AddressFields() {
const [form, fields] = useForm({
defaultValue: { address: { street: '', city: '' } },
});
const address = fields.address.getFieldset();
return (
<form {...form.props}>
<input {...address.street.props} />
<input {...address.city.props} />
</form>
);
}Gets the child field metadata for the nested address object, with names inferred from the parent field.
A schema contains an object such as an address with street, city, and postal-code fields.
A repeated item contains nested object properties.
A form component receives field metadata for an object and needs its children.
Call getFieldset() on the metadata for a nested object, such as fields.address.getFieldset(). The result provides the nested fields as properties, with their names inferred automatically.
Follow-up: How would you handle a nested array? Use getFieldList() for the array, then call getFieldset() on each item field.
The returned object is a fieldset containing the child field metadata. You can access members such as address.street and use their metadata to render inputs.
Follow-up: How can the nested fieldset be used with a fieldset element? Pass the parent metadata to getFieldsetProps() when native fieldset accessibility props are needed.
It replaces the older useFieldset approach for nested fields. The method is available directly on field metadata, so an additional nested-field hook or component is not required.
Follow-up: What is the analogous API for a list? Use getFieldList() on the parent list metadata, then obtain each item's fieldset.
getFieldListgetFieldsetPropsuseFormuseFormMetadata