Option to persist React Query DevTool in Production #3296
-
Option to persist React Query DevTool in ProductionAt first glance, this sounds like a bad idea but I have a point. The problem
The solution
Drawback
Best of both worlds. Does that make any sense? |
Beta Was this translation helpful? Give feedback.
Replies: 5 comments 7 replies
-
If still that isn't enough to log an error in the console, we can check the domain to show the dev tools conditionally in the prod. |
Beta Was this translation helpful? Give feedback.
-
You can just do this: |
Beta Was this translation helpful? Give feedback.
-
I am documenting this for future use!import { ReactQueryDevtools } from 'react-query/devtools'
const ReactQueryDevtoolsProduction = React.lazy(() =>
import('react-query/devtools/development').then(d => ({
default: d.ReactQueryDevtools,
}))
)
const queryClient = new QueryClient()
export default function App() {
const [showDevtools, setShowDevtools] = React.useState(false)
React.useEffect(() => {
// @ts-ignore
window.toggleDevtools = () => setShowDevtools(old => !old)
}, [])
return (
<QueryClientProvider client={queryClient} contextSharing={true}>
<App />
<ReactQueryDevtools />
{showDevtools ? (
<React.Suspense fallback={null}>
<ReactQueryDevtoolsProduction />
</React.Suspense>
) : null}
</QueryClientProvider>
)
}
// Usage
// window.toggleDevtools(true) |
Beta Was this translation helpful? Give feedback.
-
Thanks @TkDodo |
Beta Was this translation helpful? Give feedback.
-
ReminderYou need your import to reference the const ReactQueryDevtoolsProduction = React.lazy(() =>
import('react-query/devtools/development').then(d => ({
// ---------------------------^^^^^^^^^
default: d.ReactQueryDevtools,
}))
) |
Beta Was this translation helpful? Give feedback.
I am documenting this for future use!