# getErrors

> Read all, individual, or multiple currently stored form errors without running validation.

Source: https://react-hook-form.com/docs/useform/geterrors

## `getErrors:` [UseFormGetErrors](https://react-hook-form.com/ts#UseFormGetErrors) _(since v7.86.0)_

`getErrors` reads the errors currently stored in the form without running validation, subscribing to error changes, or triggering re-renders. Use [`formState.errors`](https://react-hook-form.com/docs/useform/formstate) or [`useFormState`](https://react-hook-form.com/docs/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`.                                                                              |

> **Important: Rules**
>
> - Treat returned errors as read-only. Use [`setError`](https://react-hook-form.com/docs/useform/seterror) and [`clearErrors`](https://react-hook-form.com/docs/useform/clearerrors) to update the form's stored errors.
>

### Example

---

```tsx
import { useForm } from "react-hook-form"

type FormInputs = {
  email: string
  user: {
    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>
  )
}
```

### Tips

---

- Use `getErrors` in event handlers and effects where you need the current errors but do not want a re-render. For example, in a multi-step form, find which steps have errors after validation:

  ```javascript
  const onNext = async () => {
    await trigger()
    const [account, address] = getErrors(["account", "address"])
    setStepsWithErrors({ account: !!account, address: !!address })
  }
  ```

- Do not render from `getErrors`. The value is not reactive, so the UI does not update when errors change. Use [`formState.errors`](https://react-hook-form.com/docs/useform/formstate) or [`ErrorMessage`](https://react-hook-form.com/docs/useformstate/errormessage) for UI.
