This repository was archived by the owner on May 19, 2025. It is now read-only.
forked from replayio-public/react-hook-form
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwatch.tsx
More file actions
56 lines (46 loc) · 1.54 KB
/
watch.tsx
File metadata and controls
56 lines (46 loc) · 1.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import React from 'react';
import { useForm } from 'react-hook-form';
const Watch: React.FC = () => {
const { register, handleSubmit, watch } = useForm<{
testSingle: string;
test: string[];
testObject: {
firstName: string;
lastName: string;
};
toggle: string;
}>();
const onSubmit = () => {};
const test = watch('test');
const testObject = watch('testObject');
const testSingle = watch('testSingle');
const testArray = watch(['test.0', 'test.1']);
const toggle = watch('toggle');
const watchAll = watch();
return (
<form onSubmit={handleSubmit(onSubmit)}>
<input {...register('testSingle')} placeholder="testSingle" />
{testSingle === 'testSingle' && (
<div id="HideTestSingle">Hide Content TestSingle</div>
)}
<input {...register('test.0')} placeholder="test[0]" />
<input {...register('test.1')} placeholder="test[1]" />
<div id="testData">{JSON.stringify(test)}</div>
<div id="testArray">{JSON.stringify(testArray)}</div>
<input
{...register('testObject.firstName')}
placeholder="testObject.firstName"
/>
<input
{...register('testObject.lastName')}
placeholder="testObject.lastName"
/>
<div id="testObject">{JSON.stringify(testObject)}</div>
<input type="checkbox" {...register('toggle')} />
{toggle && <div id="hideContent">Hide Content</div>}
<div id="watchAll">{JSON.stringify(watchAll)}</div>
<button>Submit</button>
</form>
);
};
export const watch = Watch;