()
| 3 | import { useForm } from 'react-hook-form'; |
| 4 | |
| 5 | export default function App() { |
| 6 | const { register, handleSubmit, reset } = useForm(); |
| 7 | const onSubmit = (data) => { |
| 8 | alert(JSON.stringify(data)); |
| 9 | }; |
| 10 | |
| 11 | useEffect(() => { |
| 12 | // you can use `async` server requests to populate your form! |
| 13 | setTimeout(() => { |
| 14 | reset({ |
| 15 | firstName: 'bill', |
| 16 | lastName: 'luo', |
| 17 | }); |
| 18 | }, 2000); |
| 19 | }, [reset]); |
| 20 | |
| 21 | return ( |
| 22 | <form onSubmit={handleSubmit(onSubmit)}> |
| 23 | <h1>Async Set Form Values</h1> |
| 24 | <label>First name</label> |
| 25 | <input {...register('firstName')} /> |
| 26 | |
| 27 | <label>Last name</label> |
| 28 | <input {...register('lastName')} /> |
| 29 | <input type="submit" /> |
| 30 | </form> |
| 31 | ); |
| 32 | } |
nothing calls this directly
no test coverage detected