Skip to content

Commit 294337a

Browse files
committed
docs: document devtools in production
1 parent 1118fac commit 294337a

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed

docs/devtools.md

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,3 +87,47 @@ Use these options to style the dev tools.
8787
- The standard React style object used to style a component with inline styles
8888
- `className: string`
8989
- The standard React className property used to style a component with classes
90+
91+
## Devtools in production
92+
93+
Devtools are excluded in production builds. However, it might be desirable to lazy load the devtools in production:
94+
95+
```tsx
96+
import * as React from 'react'
97+
import { QueryClient, QueryClientProvider } from '@tanstack/react-query'
98+
import { ReactQueryDevtools } from '@tanstack/react-query-devtools'
99+
import { Example } from './Example'
100+
101+
const queryClient = new QueryClient()
102+
103+
const ReactQueryDevtoolsProduction = React.lazy(() =>
104+
import('@tanstack/react-query-devtools/build/lib/index.prod.js').then(d => ({
105+
default: d.ReactQueryDevtools
106+
}))
107+
)
108+
109+
function App() {
110+
const [showDevtools, setShowDevtools] = React.useState(false)
111+
112+
React.useEffect(() => {
113+
// @ts-ignore
114+
window.toggleDevtools = () => setShowDevtools(old => !old)
115+
}, [])
116+
117+
return (
118+
<QueryClientProvider client={queryClient}>
119+
<Example />
120+
<ReactQueryDevtools initialIsOpen />
121+
{ showDevtools && (
122+
<React.Suspense fallback={null}>
123+
<ReactQueryDevtoolsProduction />
124+
</React.Suspense>
125+
)}
126+
</QueryClientProvider>
127+
);
128+
}
129+
130+
export default App
131+
```
132+
133+
With this, calling `window.toggleDevtools()` will download the devtools bundle and show them.

0 commit comments

Comments
 (0)