reactjs - 如何解决 TypeError : path. split is not a function

标签 reactjs typeerror react-hook-form

现在我正在使用 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>
    );
}

即使我复制并粘贴了示例代码,也出现了同样的错误,那么我该如何解决呢?
错误代码如下。
enter image description here

最佳答案

我认为您使用的是带有 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/

相关文章:

javascript - for 循环中的 Addeventlistener 有效,但调试器向我抛出一个未捕获的 TypeError : Cannot read property 'addEventListener' of undefined

javascript - 当我折叠、添加或删除面板时,React-hook-form 字段值会丢失

reactjs - 使用 React-Hook-Forms 通过子组件传递方法

node.js - React-Router Router.HistoryLocation 刷新页面

javascript - React JS - 在数组末尾停止无限滚动

python - "Can' t convert 'int' object to str implicitly”错误(Python)

python - 为什么 int(string) 给出值错误

javascript - 使用 React-Select 中的 AsyncSelect 的 React Hook 表单

javascript - React 共享组件/缓存

javascript - 如果用户引用用户名和 userId 引用 id,有任何方法可以使 "const {user, userId} = this.state"工作