mirror of
https://github.com/ershisan99/db-studio.git
synced 2025-12-16 12:33:05 +00:00
33 lines
692 B
TypeScript
33 lines
692 B
TypeScript
import { Input, type InputProps } from "@/components/ui";
|
|
import {
|
|
type Control,
|
|
type FieldValues,
|
|
type UseControllerProps,
|
|
useController,
|
|
} from "react-hook-form";
|
|
|
|
type Props<T extends FieldValues> = Omit<
|
|
UseControllerProps<T>,
|
|
"control" | "defaultValue" | "rules"
|
|
> &
|
|
Omit<InputProps, "value" | "onChange"> & { control: Control<T> };
|
|
|
|
export const FormInput = <T extends FieldValues>({
|
|
control,
|
|
name,
|
|
disabled,
|
|
shouldUnregister,
|
|
...rest
|
|
}: Props<T>) => {
|
|
const {
|
|
field,
|
|
fieldState: { error },
|
|
} = useController({
|
|
control,
|
|
name,
|
|
disabled,
|
|
shouldUnregister,
|
|
});
|
|
return <Input errorMessage={error?.message} {...field} {...rest} />;
|
|
};
|