我正在处理Reactjs和nextjs,现在我正在尝试“验证表单”,但我得到以下错误找不到名称'handleSubmit'现在我正在使用以下代码,但不为我工作
import Head from 'next/head'
import Image from 'next/image'
import { Inter } from '@next/font/google'
import styles from '@/styles/Home.module.css'
const inter = Inter({ subsets: ['latin'] })
import { useForm } from "react-hook-form";
const checkauth=()=>
{
alert('Hello world');
}
export default function Home() {
return (
<>
<div className="container">
<div className="screen">
<div className="screen__content">
<form className="login" onSubmit={handleSubmit(checkauth)}>
<div className="login__field">
<i className="login__icon fas fa-user" />
<input
type="text"
className="login__input"
placeholder="User name / Email"
/>
</div>
<div className="login__field">
<i className="login__icon fas fa-lock" />
<input
type="password"
className="login__input"
placeholder="Password"
/>
</div>
<button className="button login__submit">
<span className="button__text">Log In Now</span>
<i className="button__icon fas fa-chevron-right" />
</button>
</form>
</div>
</div>
</div>
</>
)
}
2条答案
按热度按时间8ehkhllq1#
看起来您正在尝试使用
handleSubmit
函数,但该函数尚未定义。请在Home
组件内从useForm
析构该函数。下面是一个示例代码:
阅读react-hook-form文档
qlckcl4x2#
必须从useForm获取handleSubmit函数
现在,要调用它,请执行以下操作