How To Create Forms In React — React Hook Form Tutorial
Mar 11, 2021
Installation
npm install react-hook-form
Example
import React from "react";import "./style.css";import { useForm } from "react-hook-form";export default function App() {const { register, handleSubmit, watch, errors } = useForm();const onSubmit = data => console.log(data);return (<div><form onSubmit={handleSubmit(onSubmit)}><input type="text" placeholder="Email" name="email" ref={register} /><input type="password"
placeholder="Password"
name="password"
ref={register({required: 'Password is required',
minLength: {value: 8, message: 'Too short' }})} />{errors.password && errors.password.message}<input type="submit" /></form></div>);}