现在我正在使用 react-hook-form用于登录验证。
但是,类型错误:path.split 不是函数 错误继续发生时
ref={注册} 在输入标签中输入。
import React from 'react';
import {useForm} from "react-hook-form";
import './Auth.css';
export default function Register() {
const {register, errors, watch} = useForm();
return (
<div>
<form>
<label>Email</label>
<input type="email" name="email" ref={register({ required: true})} />
<label>Password</label>
<input type="password" />
<label>Password Confirm</label>
<input type="password"/>
<input type="submit" />
</form>
</div>
);
}
即使我复制并粘贴了示例代码,也出现了同样的错误,那么我该如何解决呢?错误代码如下。
最佳答案
我认为您使用的是带有 v6 语法的 React Hook Form v7,这就是您收到该错误的原因。
这是一个类似的问题:https://github.com/react-hook-form/react-hook-form/issues/4595
对于 v7,您必须使用 register
像那样:
<input type="email" {...register('email', { required: true })} />
或者安装 v6,文档在这里:https://react-hook-form.com/v6/api#register
关于reactjs - 如何解决 TypeError : path. split is not a function,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66970743/