mirror of
https://github.com/khairul169/code-share.git
synced 2025-04-28 16:49:36 +07:00
26 lines
621 B
TypeScript
26 lines
621 B
TypeScript
import { useForm } from "~/hooks/useForm";
|
|
import { FieldValues } from "react-hook-form";
|
|
import React from "react";
|
|
|
|
type Props<T extends FieldValues> = {
|
|
form: ReturnType<typeof useForm<T>>;
|
|
};
|
|
|
|
const FormErrorMessage = <T extends FieldValues>({ form }: Props<T>) => {
|
|
const { errors } = form.formState;
|
|
const error = Object.entries(errors)[0];
|
|
if (!error) {
|
|
return null;
|
|
}
|
|
|
|
const [key, { message }] = error as any;
|
|
|
|
return (
|
|
<div className="bg-slate-800 border border-slate-600 rounded-md px-4 py-2 text-sm mb-4">
|
|
{`${key}: ${message}`}
|
|
</div>
|
|
);
|
|
};
|
|
|
|
export default FormErrorMessage;
|