|
1 | | -import type { PLACEMENT } from '../../src/devTool'; |
2 | | -import { DevTool } from '../../src/devTool'; |
3 | 1 | import React from 'react'; |
4 | | -import { useForm } from 'react-hook-form'; |
5 | 2 | import { Link, Route, Routes, useParams } from 'react-router-dom'; |
| 3 | +import { PLACEMENT } from '../../src/position'; |
6 | 4 | import './App.css'; |
| 5 | +import Form1 from './forms/Form1'; |
| 6 | +import Form2 from './forms/Form2'; |
7 | 7 |
|
8 | | -const Form: React.FC = () => { |
| 8 | +const Page: React.FC<{ multiple?: boolean }> = ({ multiple }) => { |
9 | 9 | const params = useParams(); |
10 | | - |
11 | | - const { register, control, handleSubmit } = useForm<{ |
12 | | - firstName: string; |
13 | | - lastName: string; |
14 | | - custom: string; |
15 | | - ha: { |
16 | | - test: string; |
17 | | - }; |
18 | | - }>({ |
19 | | - mode: 'onChange', |
20 | | - defaultValues: { |
21 | | - firstName: '', |
22 | | - lastName: '', |
23 | | - ha: { |
24 | | - test: '', |
25 | | - }, |
26 | | - }, |
27 | | - }); |
28 | | - |
29 | | - React.useEffect(() => { |
30 | | - register('custom'); |
31 | | - }, [register]); |
32 | | - |
33 | 10 | return ( |
34 | 11 | <> |
35 | | - <form onSubmit={handleSubmit((data) => data)}> |
36 | | - <h1> |
37 | | - <span role="img" aria-label="devTool"> |
38 | | - 🔧 |
39 | | - </span>{' '} |
40 | | - DevTools |
41 | | - </h1> |
42 | | - <p style={{ textAlign: 'center' }}> |
43 | | - React Hook Form DevTools to help debug forms. |
44 | | - </p> |
45 | | - <label>First Name</label> |
46 | | - <input {...register('firstName', { required: true })} /> |
47 | | - <input {...register('ha.test', { required: true })} /> |
48 | | - |
49 | | - <label>Last Name</label> |
50 | | - <input {...register('lastName', { required: true })} /> |
51 | | - |
52 | | - <input style={{ fontWeight: 400 }} type="submit" /> |
53 | | - </form> |
54 | | - |
55 | | - <DevTool |
56 | | - control={control} |
57 | | - placement={(params?.placement as PLACEMENT) ?? 'top-right'} |
58 | | - /> |
| 12 | + <h1> |
| 13 | + <span role="img" aria-label="devTool"> |
| 14 | + 🔧 |
| 15 | + </span>{' '} |
| 16 | + DevTools |
| 17 | + </h1> |
| 18 | + <p style={{ textAlign: 'center' }}> |
| 19 | + React Hook Form DevTools to help debug forms. |
| 20 | + </p> |
| 21 | + <Form1 placement={params?.placement as PLACEMENT} /> |
| 22 | + {multiple && <Form2 />} |
59 | 23 | </> |
60 | 24 | ); |
61 | 25 | }; |
62 | 26 |
|
63 | | -const App = () => { |
| 27 | +const App: React.FC = () => { |
64 | 28 | return ( |
65 | 29 | <div className="App"> |
66 | 30 | <nav> |
67 | 31 | <Link to="/">Default</Link> |
68 | 32 | <Link to="placement/top-left">Top Left</Link> |
69 | 33 | <Link to="placement/bottom-left">Bottom Left</Link> |
70 | 34 | <Link to="placement/bottom-right">Bottom Right</Link> |
| 35 | + <Link to="multiple">Multiple</Link> |
71 | 36 | </nav> |
72 | 37 | <Routes> |
73 | | - <Route path="/" element={<Form />} /> |
74 | | - <Route path="placement/:placement" element={<Form />} /> |
| 38 | + <Route path="/" element={<Page />} /> |
| 39 | + <Route path="placement/:placement" element={<Page />} /> |
| 40 | + <Route path="multiple" element={<Page multiple />} /> |
75 | 41 | </Routes> |
76 | 42 | </div> |
77 | 43 | ); |
|
0 commit comments