</> getErrors: UseFormGetErrors
Note: This API is planned for an upcoming React Hook Form release and has not yet shipped.
getErrors reads the errors currently stored in the form without running validation, subscribing to error changes, or triggering re-renders. Use formState.errors or useFormState for reactive error UI.
Props
| Name | Type | Description |
|---|---|---|
name | undefined | Returns all currently stored errors. |
| string | Returns the error at a field, parent, or global error path (root, root.*, form, or form.*), or undefined. Parent paths may return a nested error subtree. | |
| string[] | Returns one result for each path in the same order. Missing errors remain undefined. |
RULES
- Treat returned errors as read-only. Use
setErrorandclearErrorsto update the form's stored errors.
Example
import { useForm } from "react-hook-form"type FormInputs = {email: stringuser: {firstName: string}}export default function App() {const { register, getErrors } = useForm<FormInputs>({mode: "onChange",})const readErrors = () => {const allErrors = getErrors()const userErrors = getErrors("user")const [emailError, firstNameError] = getErrors(["email", "user.firstName"])console.log({allErrors,userErrors,emailError,firstNameError,})}return (<form><input {...register("email", { required: true })} /><input {...register("user.firstName", { required: true })} /><button type="button" onClick={readErrors}>Read errors</button></form>)}
Thank you for your support
If you find React Hook Form to be useful in your project, please consider starring and supporting it.