MCPcopy Create free account
hub / github.com/react-hook-form/react-hook-form / App

Function App

examples/V7/asyncSetFormValues.tsx:5–32  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

3import { useForm } from 'react-hook-form';
4
5export 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}

Callers

nothing calls this directly

Calls 4

useFormFunction · 0.85
resetFunction · 0.85
handleSubmitFunction · 0.85
registerFunction · 0.85

Tested by

no test coverage detected