1import cn from 'classnames';
2import React from 'react';
3import { FieldValues, LiteralUnion, RegisterOptions, useFormContext } from 'react-hook-form';
5type Validation = LiteralUnion<keyof RegisterOptions, string>;
7interface ErrorMessageProps<T extends FieldValues> {
9 messages: Partial<Record<Validation, string>>;
13export function ErrorMessage<T extends FieldValues>({ field, messages, className }: ErrorMessageProps<T>) {
14 const { formState } = useFormContext<T>();
15 const error = formState.errors[field];
22 <p className={cn('text-xs text-red-500', className)}>
23 {messages[error.type as Validation]}
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list