Skip to content

Commit

Permalink
Fix #153 (#155)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
jsun969 committed Jul 11, 2022
1 parent 74b4824 commit 5cf4ada
Show file tree
Hide file tree
Showing 9 changed files with 71 additions and 352 deletions.
9 changes: 4 additions & 5 deletions example/package.json
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
{
"name": "example",
"version": "0.2.0",
"name": "rhf-devtools-example",
"private": true,
"scripts": {
"dev": "vite",
"build": "tsc && vite build",
"serve": "vite preview"
},
"dependencies": {
"@hookform/devtools": "file:..",
"@reach/router": "^1.3.4",
"loglevel": "^1.7.1",
"react": "^17.0.2",
"react-dom": "^17.0.2",
"react-hook-form": "^7.3.5"
"react-hook-form": "^7.33.1",
"react-router-dom": "6"
},
"devDependencies": {
"@types/react": "^17.0.4",
Expand Down
27 changes: 14 additions & 13 deletions example/src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
import type { PLACEMENT } from '../../src/devTool';
import { DevTool } from '../../src/devTool';
import React from 'react';
import { Router, Link, RouteComponentProps } from '@reach/router';
import { useForm } from 'react-hook-form';
import { DevTool } from '@hookform/devtools';
import type { PLACEMENT } from '@hookform/devtools';
import { Link, Route, Routes, useParams } from 'react-router-dom';
import './App.css';

const Form = ({
placement = 'top-right',
}: RouteComponentProps<{
placement: PLACEMENT;
}>) => {
const Form: React.FC = () => {
const params = useParams();

const { register, control, handleSubmit } = useForm<{
firstName: string;
lastName: string;
Expand Down Expand Up @@ -54,7 +52,10 @@ const Form = ({
<input style={{ fontWeight: 400 }} type="submit" />
</form>

<DevTool control={control} placement={placement as PLACEMENT} />
<DevTool
control={control}
placement={(params?.placement as PLACEMENT) ?? 'top-right'}
/>
</>
);
};
Expand All @@ -68,10 +69,10 @@ const App = () => {
<Link to="placement/bottom-left">Bottom Left</Link>
<Link to="placement/bottom-right">Bottom Right</Link>
</nav>
<Router>
<Form path="/" />
<Form path="placement/:placement" />
</Router>
<Routes>
<Route path="/" element={<Form />} />
<Route path="placement/:placement" element={<Form />} />
</Routes>
</div>
);
};
Expand Down
7 changes: 5 additions & 2 deletions example/src/main.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
import React from 'react';
import ReactDOM from 'react-dom';
import './index.css';
import { BrowserRouter } from 'react-router-dom';
import App from './App';
import './index.css';

ReactDOM.render(
<React.StrictMode>
<App />
<BrowserRouter>
<App />
</BrowserRouter>
</React.StrictMode>,
document.getElementById('root'),
);
Loading

0 comments on commit 5cf4ada

Please sign in to comment.