我正在使用react-hook-form,我想在一个额外的组件中包含表单的某些部分。因此,我需要传递一些方法。register, control, setValue, watch方法的正确typescript types是什么?
interface INameInput {
register: any;
setValue: any;
watch: any;
control: any;
}
const NameInput: React.FC<INameInput> = (props: INameInput) => {
const { register, control, setValue, watch } = props;
return (
<>
<label>First Name</label>
<input name="firstName" ref={register} />
<label>Last Name</label>
<input name="lastName" ref={register} />
</>
);
};
export default function App() {
const { register, control, setValue, watch} = useForm<FormValues>();
return (
<form >
<NameInput
register={register}
control={control}
setValue={setValue}
watch={watch}
/>
</form>
);
}发布于 2020-12-08 15:50:13
这是一个包含导出类型列表的页面
https://react-hook-form.com/ts
我认为你想要的是以下类型
https://react-hook-form.com/ts#UseFormMethods
例如:
UseFormMethods['register']https://stackoverflow.com/questions/65179455
复制相似问题