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

Function DefaultValues

app/src/defaultValuesAsync.tsx:7–46  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

5 new Promise<T>((res) => setTimeout(() => res(data), ms));
6
7function DefaultValues() {
8 const { register } = useForm({
9 defaultValues: async () =>
10 sleep(
11 {
12 test: 'test',
13 checkbox: ['1', '2'],
14 test1: {
15 firstName: 'firstName',
16 lastName: ['lastName0', 'lastName1'],
17 deep: {
18 nest: 'nest',
19 },
20 },
21 },
22 10,
23 ),
24 });
25 const [show, setShow] = React.useState(true);
26
27 return (
28 <>
29 {show ? (
30 <form>
31 <input {...register('test')} />
32 <input {...register('test1.firstName')} />
33 <input {...register('test1.deep.nest')} />
34 <input {...register('test1.deep.nest')} />
35 <input {...register('test1.lastName.0')} />
36 <input {...register('test1.lastName.1')} />
37 <input type="checkbox" value={'1'} {...register('checkbox')} />
38 <input type="checkbox" value={'2'} {...register('checkbox')} />
39 </form>
40 ) : null}
41 <button type={'button'} id={'toggle'} onClick={() => setShow(!show)}>
42 toggle
43 </button>
44 </>
45 );
46}
47
48export default DefaultValues;

Callers

nothing calls this directly

Calls 3

useFormFunction · 0.85
registerFunction · 0.85
sleepFunction · 0.70

Tested by

no test coverage detected