# mapValidationErrors

## Call Signature

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

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

Maps validation error issues to a simple field -> message object.
Returns the first error message for each field path.

### Parameters

#### error

[`ValidationError`](https://ic-reactor.b3pay.net/v3/libs/classes/validationerror/)

### Returns

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

### Example

```tsx
const { mutate } = useActorMutation({
  functionName: "transfer",
  onError: (error) => {
    if (isValidationError(error)) {
      const fieldErrors = mapValidationErrors(error)
      // { to: "Recipient is required", amount: "Must be a number" }

      // Use with React Hook Form
      Object.entries(fieldErrors).forEach(([field, message]) => {
        form.setError(field, { message })
      })
    }
  }
})
```

## Call Signature

> **mapValidationErrors**(`error`, `options`): [`FieldErrorsMultiple`](https://ic-reactor.b3pay.net/v3/libs/type-aliases/fielderrorsmultiple/)

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

Maps validation error issues to a simple field -> message object.
Returns the first error message for each field path.

### Parameters

#### error

[`ValidationError`](https://ic-reactor.b3pay.net/v3/libs/classes/validationerror/)

#### options

##### multiple

`true`

### Returns

[`FieldErrorsMultiple`](https://ic-reactor.b3pay.net/v3/libs/type-aliases/fielderrorsmultiple/)

### Example

```tsx
const { mutate } = useActorMutation({
  functionName: "transfer",
  onError: (error) => {
    if (isValidationError(error)) {
      const fieldErrors = mapValidationErrors(error)
      // { to: "Recipient is required", amount: "Must be a number" }

      // Use with React Hook Form
      Object.entries(fieldErrors).forEach(([field, message]) => {
        form.setError(field, { message })
      })
    }
  }
})
```

## Call Signature

> **mapValidationErrors**(`error`, `options`): [`FieldErrors`](https://ic-reactor.b3pay.net/v3/libs/type-aliases/fielderrors/)

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

Maps validation error issues to a simple field -> message object.
Returns the first error message for each field path.

### Parameters

#### error

[`ValidationError`](https://ic-reactor.b3pay.net/v3/libs/classes/validationerror/)

#### options

##### multiple

`false`

### Returns

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

### Example

```tsx
const { mutate } = useActorMutation({
  functionName: "transfer",
  onError: (error) => {
    if (isValidationError(error)) {
      const fieldErrors = mapValidationErrors(error)
      // { to: "Recipient is required", amount: "Must be a number" }

      // Use with React Hook Form
      Object.entries(fieldErrors).forEach(([field, message]) => {
        form.setError(field, { message })
      })
    }
  }
})
```