首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >react-hook-form方法有哪些类型?

react-hook-form方法有哪些类型?
EN

Stack Overflow用户
提问于 2020-12-07 17:52:56
回答 1查看 695关注 0票数 2

我正在使用react-hook-form,我想在一个额外的组件中包含表单的某些部分。因此,我需要传递一些方法。register, control, setValue, watch方法的正确typescript types是什么?

Example Sandbox

代码语言:javascript
复制
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>
  );
}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-12-08 15:50:13

这是一个包含导出类型列表的页面

https://react-hook-form.com/ts

我认为你想要的是以下类型

https://react-hook-form.com/ts#UseFormMethods

例如:

代码语言:javascript
复制
UseFormMethods['register']
票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/65179455

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档