Skip to content

Commit 5cf4ada

Browse files
authored
Fix #153 (#155)
* refactor(example): use `react-router` instead of `@reach/router` * fix(example): import devtools from folder instead of package - Don't need to build and reinstall before run example - Support hot update * chore(pkg): upgrade rhf version to 7.33.1 * perf: set devtools not visible by default - Just show a devtools icon by default - The extension need time to initalize. - If show the panel, it will flash and disapper * fix(ui): storybook type error
1 parent 74b4824 commit 5cf4ada

File tree

9 files changed

+71
-352
lines changed

9 files changed

+71
-352
lines changed

example/package.json

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,17 @@
11
{
2-
"name": "example",
3-
"version": "0.2.0",
2+
"name": "rhf-devtools-example",
3+
"private": true,
44
"scripts": {
55
"dev": "vite",
66
"build": "tsc && vite build",
77
"serve": "vite preview"
88
},
99
"dependencies": {
10-
"@hookform/devtools": "file:..",
11-
"@reach/router": "^1.3.4",
1210
"loglevel": "^1.7.1",
1311
"react": "^17.0.2",
1412
"react-dom": "^17.0.2",
15-
"react-hook-form": "^7.3.5"
13+
"react-hook-form": "^7.33.1",
14+
"react-router-dom": "6"
1615
},
1716
"devDependencies": {
1817
"@types/react": "^17.0.4",

example/src/App.tsx

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
1+
import type { PLACEMENT } from '../../src/devTool';
2+
import { DevTool } from '../../src/devTool';
13
import React from 'react';
2-
import { Router, Link, RouteComponentProps } from '@reach/router';
34
import { useForm } from 'react-hook-form';
4-
import { DevTool } from '@hookform/devtools';
5-
import type { PLACEMENT } from '@hookform/devtools';
5+
import { Link, Route, Routes, useParams } from 'react-router-dom';
66
import './App.css';
77

8-
const Form = ({
9-
placement = 'top-right',
10-
}: RouteComponentProps<{
11-
placement: PLACEMENT;
12-
}>) => {
8+
const Form: React.FC = () => {
9+
const params = useParams();
10+
1311
const { register, control, handleSubmit } = useForm<{
1412
firstName: string;
1513
lastName: string;
@@ -54,7 +52,10 @@ const Form = ({
5452
<input style={{ fontWeight: 400 }} type="submit" />
5553
</form>
5654

57-
<DevTool control={control} placement={placement as PLACEMENT} />
55+
<DevTool
56+
control={control}
57+
placement={(params?.placement as PLACEMENT) ?? 'top-right'}
58+
/>
5859
</>
5960
);
6061
};
@@ -68,10 +69,10 @@ const App = () => {
6869
<Link to="placement/bottom-left">Bottom Left</Link>
6970
<Link to="placement/bottom-right">Bottom Right</Link>
7071
</nav>
71-
<Router>
72-
<Form path="/" />
73-
<Form path="placement/:placement" />
74-
</Router>
72+
<Routes>
73+
<Route path="/" element={<Form />} />
74+
<Route path="placement/:placement" element={<Form />} />
75+
</Routes>
7576
</div>
7677
);
7778
};

example/src/main.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
import React from 'react';
22
import ReactDOM from 'react-dom';
3-
import './index.css';
3+
import { BrowserRouter } from 'react-router-dom';
44
import App from './App';
5+
import './index.css';
56

67
ReactDOM.render(
78
<React.StrictMode>
8-
<App />
9+
<BrowserRouter>
10+
<App />
11+
</BrowserRouter>
912
</React.StrictMode>,
1013
document.getElementById('root'),
1114
);

0 commit comments

Comments
 (0)