import cn from 'classnames'; import React from 'react'; import { FieldValues, LiteralUnion, RegisterOptions, useFormContext } from 'react-hook-form'; type Validation = LiteralUnion; interface ErrorMessageProps { field: keyof T; messages: Partial>; className?: string; } export function ErrorMessage({ field, messages, className }: ErrorMessageProps) { const { formState } = useFormContext(); const error = formState.errors[field]; if (!error) { return null; } return (

{messages[error.type as Validation]}

) }