/
githubmirror
/
react-hook-form
Обзор
Документация
Войти
/
githubmirror
/
react-hook-form
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
examples/V7/validationOnFieldChange.tsx
49 строк
1 KB
Bill
🌐 prettier the entire code base (#5118)
10 май 2021, 10:18
Не верифицирован
10 май 2021, 10:18
10fe39d
Код
Авторство
О чём код?
import React from 'react'; import ReactDOM from 'react-dom'; import { useForm } from 'react-hook-form'; export default function App() { const { register, formState: { errors }, handleSubmit, } = useForm({ mode: 'onChange', }); const onSubmit = (data) => { alert(JSON.stringify(data)); }; return ( <div className="App"> <form onSubmit={handleSubmit(onSubmit)}> <div> <label htmlFor="firstName">First Name</label> <input placeholder="bill" {...register('firstName', { required: true })} /> {errors.firstName && 'This is required'} </div> <div> <label htmlFor="lastName">Last Name</label> <input placeholder="luo" {...register('lastName', { required: true })} /> {errors.lastName && 'This is required'} </div> <div> <label htmlFor="email" placeholder="bluebill1049@hotmail.com"> Email </label> <input {...register('email', { required: true })} /> {errors.email && 'This is required'} </div> <button type="submit">Submit</button> </form> </div> ); }