useFormState returns errors and isValid for the entire form #12964
Replies: 1 comment
|
For a single field, use const {
field,
fieldState: { invalid, error, isDirty, isTouched },
} = useController({
control,
name: 'email',
})If the component is not controlling the input, subscribe narrowly with const formState = useFormState({
control,
name: 'email',
exact: true,
})
const { invalid, error } = getFieldState(
'email',
formState,
)For a section containing multiple fields, subscribe to that explicit list: const names = ['address.street', 'address.city'] as const
const { errors } = useFormState({ control, name: names, exact: true })Then derive section validity from those paths, or call The Docs: https://react-hook-form.com/docs/useformstate and https://react-hook-form.com/docs/useform/getfieldstate |
Uh oh!
There was an error while loading. Please reload this page.
Is there a way to get
isValidand errors in each form component I useuseFormState.All reactions