/
githubmirror
/
react-hook-form
Обзор
Документация
Войти
/
githubmirror
/
react-hook-form
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
examples/V7/getValuesCompareFields.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 }, getValues, handleSubmit, } = useForm(); return ( <div className="App"> <h1>getValue - Compare Field Values</h1> <form onSubmit={handleSubmit((data) => console.log(data))}> <label>New Password: </label> <input name="password" ref={register({ required: 'Password is required!' })} /> {errors.password && ( <p style={{ color: 'white' }}>{errors.password.message}</p> )} <label>Confirm Password: </label> <input name="passwordConfirmation" ref={register({ required: 'Please confirm password!', validate: { matchesPreviousPassword: (value) => { const { password } = getValues(); return password === value || 'Passwords should match!'; }, }, })} /> {errors.passwordConfirmation && ( <p style={{ color: 'white' }}> {errors.passwordConfirmation.message} </p> )} <button type="submit">Trigger</button> </form> </div> ); }