File size: 668 Bytes
1e92f2d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import React from 'react';
import { useForm } from 'react-hook-form';

export default function App() {
  const { errors, handleSubmit, register } = useForm();

  const onSubmit = (data) => {
    console.log({ data });
  };

  return (
    <form onSubmit={handleSubmit(onSubmit)} noValidate>
      <label htmlFor="email">Email</label>
      <input
        name="email"
        type="email"
        ref={register({
          required: 'Email is required',
          validate: (value) =>
            value.includes('@') || "Email must include '@' symbol",
        })}
      />
      {errors.email && errors.email.message}
      <input type="submit" />
    </form>
  );
}