Skip to content

Option to persist React Query DevTool in Production #3296

Answered by noor-codes
noor-codes asked this question in General
Discussion options

You must be logged in to vote

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}>

Replies: 5 comments 7 replies

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
2 replies
@noor-codes
Comment options

@noor-codes
Comment options

Comment options

You must be logged in to vote
0 replies
Answer selected by noor-codes
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
5 replies
@bgoette
Comment options

@JonParton
Comment options

@TkDodo
Comment options

@JonParton
Comment options

@p0zi
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
6 participants