/
githubmirror
/
react-hook-form
Обзор
Документация
Войти
/
githubmirror
/
react-hook-form
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
examples/V7/triggerFieldValidation.tsx
36 строк
817 B
Mert Ciflikli
🔖 fix typos in examples and source code (#6531)
12 сен 2021, 13:20
Не верифицирован
12 сен 2021, 13:20
ecbd848
Код
Авторство
О чём код?
import React from 'react'; import { useForm } from 'react-hook-form'; export default function App() { const { register, formState: { errors }, trigger, handleSubmit, } = useForm(); console.log('errors', errors); return ( <form onSubmit={handleSubmit((data) => console.log(data))}> <h1>validationField</h1> <label>First name: </label> <input {...register('firstName', { required: true })} /> <label>Last name: </label> <input {...register('lastName', { required: true })} /> <button type="button" onClick={async () => { const result = await trigger(['firstName', 'lastName']); if (result) { console.log('Valid input'); } }} > Trigger </button> </form> ); }