Skip to content

Commit 9cd746a

Browse files
committed
feat: added devtools component that render conditionally
1 parent 46277a3 commit 9cd746a

File tree

3 files changed

+474
-3
lines changed

3 files changed

+474
-3
lines changed

frontend/components/Devtools.tsx

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import { type ReactNode } from 'react'
2+
import { useEffect, useState } from 'react'
3+
import { createPortal } from 'react-dom'
4+
5+
export default function Devtools({ jotai, reactQuery }: { jotai?: boolean; reactQuery?: boolean }) {
6+
const [DevtoolsComponents, setDevtoolsComponents] = useState<ReactNode | undefined>()
7+
8+
useEffect(() => {
9+
if (import.meta.env.DEV) {
10+
Promise.all([
11+
jotai ? import('jotai-devtools') : undefined,
12+
reactQuery ? import('@tanstack/react-query-devtools') : undefined,
13+
jotai ? import('jotai-devtools/styles.css') : undefined
14+
]).then(([jotaiDevtools, reactQueryDevtools]) => {
15+
const DevelopmentToolsUI = (
16+
<>
17+
{jotai && jotaiDevtools ? <jotaiDevtools.DevTools position="bottom-right" /> : undefined}
18+
{reactQuery && reactQueryDevtools ? (
19+
<reactQueryDevtools.ReactQueryDevtools initialIsOpen={false} position="bottom" />
20+
) : undefined}
21+
</>
22+
)
23+
setDevtoolsComponents(DevelopmentToolsUI)
24+
})
25+
}
26+
}, [jotai, reactQuery])
27+
28+
if (!import.meta.env.DEV) return
29+
30+
return DevtoolsComponents ? createPortal(DevtoolsComponents, document.body) : undefined
31+
}

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
"immer": "^10.1.1",
4444
"jotai": "^2.8.3",
4545
"jotai-immer": "^0.4.1",
46+
"jotai-devtools": "^0.10.1",
4647
"localforage": "^1.10.0",
4748
"lucide-react": "^0.397.0",
4849
"react": "^18.3.1",
@@ -141,4 +142,4 @@
141142
"vite-tsconfig-paths": "^5.0.1",
142143
"vitest": "^1.6.0"
143144
}
144-
}
145+
}

0 commit comments

Comments
 (0)