小编Aid*_*osh的帖子

类型错误:无法读取 null 的属性(读取“useRef”)

我正在使用 Next.js、TypeScript、sanity 和 tailwindcss。我尝试使用react-hook-form,但收到错误。

我试过了:

  • 将函数更改Post为箭头函数
  • 将函数更改Post为 const 函数
  • 将接口更改IFormInput为类型

这是错误所在:

  23 |      formState: { errors },
> 24 |  } = useForm<IFormInput>();
     |            ^
  25 | 
  26 |  return (
  27 |      <main>
Run Code Online (Sandbox Code Playgroud)

这是我在页面文件夹中的代码([slug].tsx):

import { useForm, SubmitHandler } from "react-hook-form";

interface IFormInput {
    _id: string;
    name: string;
    email: string;
    comment: string;
}

function Post({ post }: Props) {
 const { register, handleSubmit, formState: { errors } } = useForm<IFormInput>();

 return …
Run Code Online (Sandbox Code Playgroud)

typescript reactjs next.js react-hook-form

12
推荐指数
2
解决办法
7万
查看次数

标签 统计

next.js ×1

react-hook-form ×1

reactjs ×1

typescript ×1