# extractValidationErrors

> **extractValidationErrors**(`error`): [`FieldErrors`](https://ic-reactor.b3pay.net/v3/libs/type-aliases/fielderrors/) \| `null`

Defined in: [react/src/validation.ts:165](https://github.com/B3Pay/ic-reactor/blob/70bedf3c8779611a3b35710510442dee7f630b87/packages/react/src/validation.ts#L165)

Checks if a given error is a ValidationError and optionally
extracts field errors in one step.

## Parameters

### error

`unknown`

## Returns

[`FieldErrors`](https://ic-reactor.b3pay.net/v3/libs/type-aliases/fielderrors/) \| `null`

## Example

```tsx
const { mutateAsync } = useActorMutation({ functionName: "transfer" })

const handleSubmit = async (data) => {
  try {
    await mutateAsync([data])
  } catch (error) {
    const fieldErrors = extractValidationErrors(error)
    if (fieldErrors) {
      // Handle validation errors
      Object.entries(fieldErrors).forEach(([field, message]) => {
        form.setError(field, { message })
      })
    } else {
      // Handle other errors
      console.error(error)
    }
  }
}
```