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。
您的代码是正确的。我认为问题与您的第三方软件包安装有关。
首先卸载你的反应钩子表单
然后使用
npm
或 yarn
安装它。
确保您的网络连接正常(如果您使用 VPN,请将其关闭)
npm cache clean --force
再次运行您的应用程序并检查结果。如果你看到react-hook-form的github,有useForm.ts文件并且导出得很好。