nextjs中react hook表单中useForm导入错误

问题描述 投票:0回答:1
import { useForm } from 'react-hook-form';

export default function Register() {
  const { register, handleSubmit, formState: { errors } } = useForm();

  const onSubmit = async (data) => {
    console.log(data);
    
  };

使用此代码我收到错误

尝试导入错误:“useForm”未从“react-hook-form”导出(导入为“useForm”)。

我正在使用nextjs 14.2.9和react-hook-form 7.53.0。

next.js react-hook-form
1个回答
0
投票

您的代码是正确的。我认为问题与您的第三方软件包安装有关。

  • 首先卸载你的反应钩子表单

  • 然后使用

    npm
    yarn
    安装它。

确保您的网络连接正常(如果您使用 VPN,请将其关闭)

  • 最后使用此命令清除 npm 缓存
    npm cache clean --force

再次运行您的应用程序并检查结果。如果你看到react-hook-form的github,有useForm.ts文件并且导出得很好。

© www.soinside.com 2019 - 2024. All rights reserved.