Open History to see the last commit
1---
2id: devtools
3title: Devtools
4---
5β
6Wave your hands in the air and shout hooray because React Query comes with dedicated devtools! π₯³
7β
8When you begin your React Query journey, you'll want these devtools by your side. They help visualize all of the inner workings of React Query and will likely save you hours of debugging if you find yourself in a pinch!
9β
10> Please note that for now, the devtools **do not support React Native**. If you would like to help us make the devtools platform agnostic, please let us know!
11β
12> However, an external tool is available that enables the use of React Query DevTools with React Native projects. Find out more and contribute on [GitHub](https://github.com/LovesWorking/react-query-external-sync)..
13β
14> Also note that you can use these devtools to observe queries, but **not mutations**
15β
16## Install and Import the Devtools
17β
18The devtools are a separate package that you need to install:
19β
20```bash
21$ npm i @tanstack/react-query-devtools
22# or
23$ pnpm add @tanstack/react-query-devtools
24# or
25$ yarn add @tanstack/react-query-devtools
26# or
27$ bun add @tanstack/react-query-devtools
28```
29β
30For Next 13+ App Dir you must install it as a dev dependency for it to work.
31β
32You can import the devtools like this:
33β
34```tsx
35import { ReactQueryDevtools } from '@tanstack/react-query-devtools'
36```
37β
38By default, React Query Devtools are only included in bundles when `process.env.NODE_ENV === 'development'`, so you don't need to worry about excluding them during a production build.
39β
40## Floating Mode
41β
42Floating Mode will mount the devtools as a fixed, floating element in your app and provide a toggle in the corner of the screen to show and hide the devtools. This toggle state will be stored and remembered in localStorage across reloads.
43β
44Place the following code as high in your React app as you can. The closer it is to the root of the page, the better it will work!
45β
46```tsx
47import { ReactQueryDevtools } from '@tanstack/react-query-devtools'
48β
49function App() {
50 return (
51 <QueryClientProvider client={queryClient}>
52 {/* The rest of your application */}
53 <ReactQueryDevtools initialIsOpen={false} />
54 </QueryClientProvider>
55 )
56}
57```
58β
59### Options
60β
61- `initialIsOpen: Boolean`
62 - Set this `true` if you want the dev tools to default to being open
63- `buttonPosition?: "top-left" | "top-right" | "bottom-left" | "bottom-right" | "relative"`
64 - Defaults to `bottom-right`
65 - The position of the React Query logo to open and close the devtools panel
66 - If `relative`, the button is placed in the location that you render the devtools.
67- `position?: "top" | "bottom" | "left" | "right"`
68 - Defaults to `bottom`
69 - The position of the React Query devtools panel
70- `client?: QueryClient`,
71 - Use this to use a custom QueryClient. Otherwise, the one from the nearest context will be used.
72- `errorTypes?: { name: string; initializer: (query: Query) => TError}`
73 - Use this to predefine some errors that can be triggered on your queries. Initializer will be called (with the specific query) when that error is toggled on from the UI. It must return an Error.
74- `styleNonce?: string`
75 - Use this to pass a nonce to the style tag that is added to the document head. This is useful if you are using a Content Security Policy (CSP) nonce to allow inline styles.
76β
77## Devtools in production
78β
79Devtools are excluded in production builds. However, it might be desirable to lazy load the devtools in production:
80β
81```tsx
82import * as React from 'react'
83import { QueryClient, QueryClientProvider } from '@tanstack/react-query'
84import { ReactQueryDevtools } from '@tanstack/react-query-devtools'
85import { Example } from './Example'
86β
87const queryClient = new QueryClient()
88β
89const ReactQueryDevtoolsProduction = React.lazy(() =>
90 import('@tanstack/react-query-devtools/build/modern/production.js').then(
91 (d) => ({
92 default: d.ReactQueryDevtools,
93 }),
94 ),
95)
96β
97function App() {
98 const [showDevtools, setShowDevtools] = React.useState(false)
99β
100 React.useEffect(() => {
101 // @ts-expect-error
102 window.toggleDevtools = () => setShowDevtools((old) => !old)
103 }, [])
104β
105 return (
106 <QueryClientProvider client={queryClient}>
107 <Example />
108 <ReactQueryDevtools initialIsOpen />
109 {showDevtools && (
110 <React.Suspense fallback={null}>
111 <ReactQueryDevtoolsProduction />
112 </React.Suspense>
113 )}
114 </QueryClientProvider>
115 )
116}
117β
118export default App
119```
120β
121With this, calling `window.toggleDevtools()` will download the devtools bundle and show them.
122β
123### Modern bundlers
124β
125If your bundler supports package exports, you can use the following import path:
126β
127```tsx
128const ReactQueryDevtoolsProduction = React.lazy(() =>
129 import('@tanstack/react-query-devtools/production').then((d) => ({
130 default: d.ReactQueryDevtools,
131 })),
132)
133```
134β
135For TypeScript, you would need to set `moduleResolution: 'nodenext'` in your tsconfig, which requires at least TypeScript v4.7.