【发布时间】:2022-01-23 06:23:41
【问题描述】:
在 Typescript 中使用 react-hook-form 时,有一个组件会发送一些 props,register 就是其中之一。
问题在于它在接口中声明时的类型:
export interface MyProps {
title: string;
...
register: (string | undefined) => void;
}
在这里声明register的正确方法是什么?
也尝试过:
import { RegisterOptions } from 'react-hook-form';
export interface MyProps {
title: string;
...
register: RegisterOptions;
}
【问题讨论】:
-
您使用的是 react-hook-form 版本 6 还是 7?因为它从一个版本到另一个版本发生了很大变化。
-
根据 package.json 是
"react-hook-form": "^7.15.2", -
只需查看文档。类型在页面顶部react-hook-form.com/api/useform/register
-
@Khorne07 输入它作为答案.. 你可以获得积分
标签: javascript reactjs typescript typescript-typings react-hook-form