[英]Unable to bind a react-form-hook to custom component
I'm trying to bind a react-form-hook to a custom control(reactprime), but when I bind the control, it indicastes that:我正在尝试将 react-form-hook 绑定到自定义控件(reactprime),但是当我绑定控件时,它表明:
Type 'Control<ConfigureData, any>' is not assignable to type 'Control<FieldValues, any>'.
The types of '_options.resolver' are incompatible between these types.
Type 'Resolver<ConfigureData, any> | undefined' is not assignable to type 'Resolver<FieldValues, any> | undefined'.
Type 'Resolver<ConfigureData, any>' is not assignable to type 'Resolver<FieldValues, any>'.ts(2322)
ConfigureData is the type of my form. ConfigureData 是我的表单类型。
Here is how I declared it:这是我声明它的方式:
type ConfigureData = {
title: string;
description: string;
startHour: number;
endHour: number;
isWorkingMonday: boolean;
isWorkingTuesday: boolean;
isWorkingWednesday: boolean;
isWorkingThursday: boolean;
isWorkingFriday: boolean;
isWorkingSaturday: boolean;
isWorkingSunday: boolean;
};
const schema = yup
.object({
title: yup.string().required(),
description: yup.string().required(),
})
.required();
const {
control,
register,
handleSubmit,
reset,
formState: { errors },
} = useForm<ConfigureData>({ resolver: yupResolver(schema), defaultValues: { isWorkingMonday: true } });
and here is how I'm trying to use it:这就是我尝试使用它的方式:
<Controller control={control} render={({ field, fieldState }) => <InputSwitch></InputSwitch>} />
But it doesn't let me assign control to the control prop.但它不允许我将控制权分配给 control 道具。 Not sure what I'm missing, I didn't find example of usages of the controller with a typed model?
不知道我错过了什么,我没有找到 controller 的用法示例,类型为 model?
If I remove all my generic types, it seems to work, but I would like to continue to use them.如果我删除所有泛型类型,它似乎可以工作,但我想继续使用它们。
You can try你可以试试
import { FieldValues } from 'react-hook-form';从 'react-hook-form' 导入 { FieldValues };
const { control, register, handleSubmit, reset, formState: { errors }, } = useForm({ resolver: yupResolver(schema), defaultValues: { isWorkingMonday: true } }) as FieldValues; const { control, register, handleSubmit, reset, formState: { errors }, } = useForm({ resolver: yupResolver(schema), defaultValues: { isWorkingMonday: true } }) as FieldValues;
as作为
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.