使用代码和示例构建自己的表单。
您可以通过拖放重新排列,删除和编辑每个表格。
当您对表单进行更改时,代码部分将被更新,您也可以复制代码。
import React from 'react'; import { useForm } from 'react-hook-form'; export default function App() { const { register, handleSubmit, formState: { errors } } = useForm(); const onSubmit = data => console.log(data); console.log(errors); return ( <form onSubmit={handleSubmit(onSubmit)}> <input type="text" placeholder="First name" {...register("First name", {required: true, maxLength: 80})} /> <input type="text" placeholder="Last name" {...register("Last name", {required: true, maxLength: 100})} /> <input type="text" placeholder="Email" {...register("Email", {required: true, pattern: /^\S+@\S+$/i})} /> <input type="tel" placeholder="Mobile number" {...register("Mobile number", {required: true, minLength: 6, maxLength: 12})} /> <select {...register("Title", { required: true })}> <option value="Mr">Mr</option> <option value="Mrs">Mrs</option> <option value="Miss">Miss</option> <option value="Dr">Dr</option> </select> <input {...register("Developer", { required: true })} type="radio" value="Yes" /> <input {...register("Developer", { required: true })} type="radio" value="No" /> <input type="submit" /> </form> ); }
查看React Hook Form文档,了解所有关于API的信息。