/
githubmirror
/
react-hook-form
Обзор
Документация
Войти
/
githubmirror
/
react-hook-form
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
examples/V7/asyncSetFormValues.tsx
32 строки
783 B
Mert Ciflikli
🔖 fix typos in examples and source code (#6531)
12 сен 2021, 13:20
Не верифицирован
12 сен 2021, 13:20
ecbd848
Код
Авторство
О чём код?
import React, { useEffect } from 'react'; import ReactDOM from 'react-dom'; import { useForm } from 'react-hook-form'; export default function App() { const { register, handleSubmit, reset } = useForm(); const onSubmit = (data) => { alert(JSON.stringify(data)); }; useEffect(() => { // you can use `async` server requests to populate your form! setTimeout(() => { reset({ firstName: 'bill', lastName: 'luo', }); }, 2000); }, [reset]); return ( <form onSubmit={handleSubmit(onSubmit)}> <h1>Async Set Form Values</h1> <label>First name</label> <input {...register('firstName')} /> <label>Last name</label> <input {...register('lastName')} /> <input type="submit" /> </form> ); }