-
Notifications
You must be signed in to change notification settings - Fork 54
Expand file tree
/
Copy pathApp.tsx
More file actions
52 lines (44 loc) · 1.26 KB
/
App.tsx
File metadata and controls
52 lines (44 loc) · 1.26 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
import React from 'react';
import { useForm } from 'react-hook-form';
import { DevTool } from '@hookform/devtools';
import './App.css';
const App = () => {
const { register, control, handleSubmit, formState } = useForm<{
test: string;
test1: string;
custom: string;
}>({
mode: 'onChange',
});
React.useEffect(() => {
register('custom');
}, [register]);
console.log('app', formState.touched);
console.log('app', formState.dirtyFields);
console.log('app', formState.isValid);
return (
<div className="App">
<form onSubmit={handleSubmit((d) => console.log(d))}>
<h1>
<span role="img" aria-label="devTool">
🔧
</span>{' '}
DevTools
</h1>
<p style={{ textAlign: 'center' }}>
React Hook Form DevTools to help debug forms.
</p>
<label>First Name</label>
<input
name="thisNameHasBeenMadeLongForThePurposesOfDemonstration"
ref={register({ required: true })}
/>
<label>Last Name</label>
<input name="lastName" ref={register({ required: true })} />
<input style={{ fontWeight: 400 }} type="submit" />
</form>
<DevTool control={control} />
</div>
);
};
export default App;