The Field component manages individual field state, validation, and subscriptions. It can be used in two ways:
- As a wrapper: Pass a single React element as a child. The
Field will automatically inject controlled props (like value and onChange) into that child. - As a render prop: Pass a function as a child. This function receives
control, meta, and the form instance, allowing for highly customized UI.
control contains the props needed to drive the input (e.g., value, onChange), while meta contains the field's status (e.g., errors, touched, validating).
// Option 1: Wrapper pattern
<Field name="username">
<Input />
</Field>
// Option 2: Render props pattern
<Field name="username">
{(control, meta, form) => (
<div>
<Input {...control} />
{meta.errors.map(err => <span key={err}>{err}</span>)}
</div>
)}
</Field>