我正在尝试对我的表单进行验证以做出反应。我选择了“react-hook-form”库。但我不断收到错误“Path.split 不是函数。即使在使用他们网站上给出的默认示例后,我也遇到了同样的错误。这是官方网站中给出的默认代码。
import React from "react";
import { useForm } from "react-hook-form";
export default function App() {
const { register, handleSubmit, watch, errors } = useForm();
const onSubmit = data => console.log(data);
console.log(watch("example")); // watch input value by passing the name of it
return (
{/* "handleSubmit" will validate your inputs before invoking "onSubmit" */}
<form onSubmit={handleSubmit(onSubmit)}>
{/* register your input into the hook by invoking the "register" function */}
<input name="example" defaultValue="test" ref={register} />
{/* include validation with required …Run Code Online (Sandbox Code Playgroud)