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 the inner workings of React Query and will likely save you hours of debugging if you find yourself in a pinch!
9β
10> For Chrome, Firefox, and Edge users: Third-party browser extensions are available for debugging TanStack Query directly in browser DevTools. These provide the same functionality as the framework-specific devtools packages:
11>
12> - <img alt="Chrome logo" src="https://www.google.com/chrome/static/images/chrome-logo.svg" width="16" height="16" class="inline mr-1 not-prose" /> [Devtools for Chrome](https://chromewebstore.google.com/detail/tanstack-query-devtools/annajfchloimdhceglpgglpeepfghfai)
13> - <img alt="Firefox logo" src="https://upload.wikimedia.org/wikipedia/commons/a/a0/Firefox_logo%2C_2019.svg" width="16" height="16" class="inline mr-1 not-prose" /> [Devtools for Firefox](https://addons.mozilla.org/en-US/firefox/addon/tanstack-query-devtools/)
14> - <img alt="Edge logo" src="https://upload.wikimedia.org/wikipedia/commons/9/98/Microsoft_Edge_logo_%282019%29.svg" width="16" height="16" class="inline mr-1 not-prose" /> [Devtools for Edge](https://microsoftedge.microsoft.com/addons/detail/tanstack-query-devtools/edmdpkgkacmjopodhfolmphdenmddobj)
15β
16> For React Native users: A third-party native macOS app is available for debugging React Query in ANY js-based application. Monitor queries across devices in real-time. Check it out here: [rn-better-dev-tools](https://github.com/LovesWorking/rn-better-dev-tools)
17β
18> Note that since version 5, the dev tools support observing mutations as well.
19β
20## Install and Import the Devtools
21β
22The devtools are a separate package that you need to install:
23β
24```bash
25npm i @tanstack/react-query-devtools
26```
27β
28or
29β
30```bash
31pnpm add @tanstack/react-query-devtools
32```
33β
34or
35β
36```bash
37yarn add @tanstack/react-query-devtools
38```
39β
40or
41β
42```bash
43bun add @tanstack/react-query-devtools
44```
45β
46For Next 13+ App Dir you must install it as a dev dependency for it to work.
47β
48You can import the devtools like this:
49β
50```tsx
51import { ReactQueryDevtools } from '@tanstack/react-query-devtools'
52```
53β
54By 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.
55β
56## Floating Mode
57β
58Floating 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.
59β
60Place 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!
61β
62```tsx
63import { ReactQueryDevtools } from '@tanstack/react-query-devtools'
64β
65function App() {
66 return (
67 <QueryClientProvider client={queryClient}>
68 {/* The rest of your application */}
69 <ReactQueryDevtools initialIsOpen={false} />
70 </QueryClientProvider>
71 )
72}
73```
74β
75### Options
76β
77- `initialIsOpen: Boolean`
78 - Set this `true` if you want the dev tools to default to being open
79- `buttonPosition?: "top-left" | "top-right" | "bottom-left" | "bottom-right" | "relative"`
80 - Defaults to `bottom-right`
81 - The position of the React Query logo to open and close the devtools panel
82 - If `relative`, the button is placed in the location that you render the devtools.
83- `position?: "top" | "bottom" | "left" | "right"`
84 - Defaults to `bottom`
85 - The position of the React Query devtools panel
86- `client?: QueryClient`,
87 - Use this to use a custom QueryClient. Otherwise, the one from the nearest context will be used.
88- `errorTypes?: { name: string; initializer: (query: Query) => TError}[]`
89 - 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.
90- `styleNonce?: string`
91 - 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.
92- `shadowDOMTarget?: ShadowRoot`
93 - Default behavior will apply the devtool's styles to the head tag within the DOM.
94 - Use this to pass a shadow DOM target to the devtools so that the styles will be applied within the shadow DOM instead of within the head tag in the light DOM.
95β
96## Embedded Mode
97β
98Embedded mode will show the development tools as a fixed element in your application, so you can use our panel in your own development tools.
99β
100Place 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!
101β
102```tsx
103import { ReactQueryDevtoolsPanel } from '@tanstack/react-query-devtools'
104β
105function App() {
106 const [isOpen, setIsOpen] = React.useState(false)
107β
108 return (
109 <QueryClientProvider client={queryClient}>
110 {/* The rest of your application */}
111 <button
112 onClick={() => setIsOpen(!isOpen)}
113 >{`${isOpen ? 'Close' : 'Open'} the devtools panel`}</button>
114 {isOpen && <ReactQueryDevtoolsPanel onClose={() => setIsOpen(false)} />}
115 </QueryClientProvider>
116 )
117}
118```
119β
120### Options
121β
122- `style?: React.CSSProperties`
123 - Custom styles for the devtools panel
124 - Default: `{ height: '500px' }`
125 - Example: `{ height: '100%' }`
126 - Example: `{ height: '100%', width: '100%' }`
127- `onClose?: () => unknown`
128 - Callback function that is called when the devtools panel is closed
129- `client?: QueryClient`,
130 - Use this to use a custom QueryClient. Otherwise, the one from the nearest context will be used.
131- `errorTypes?: { name: string; initializer: (query: Query) => TError}[]`
132 - 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.
133- `styleNonce?: string`
134 - 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.
135- `shadowDOMTarget?: ShadowRoot`
136 - Default behavior will apply the devtool's styles to the head tag within the DOM.
137 - Use this to pass a shadow DOM target to the devtools so that the styles will be applied within the shadow DOM instead of within the head tag in the light DOM.
138β
139## Devtools in production
140β
141Devtools are excluded in production builds. However, it might be desirable to lazy load the devtools in production:
142β
143```tsx
144import * as React from 'react'
145import { QueryClient, QueryClientProvider } from '@tanstack/react-query'
146import { ReactQueryDevtools } from '@tanstack/react-query-devtools'
147import { Example } from './Example'
148β
149const queryClient = new QueryClient()
150β
151const ReactQueryDevtoolsProduction = React.lazy(() =>
152 import('@tanstack/react-query-devtools/build/modern/production.js').then(
153 (d) => ({
154 default: d.ReactQueryDevtools,
155 }),
156 ),
157)
158β
159function App() {
160 const [showDevtools, setShowDevtools] = React.useState(false)
161β
162 React.useEffect(() => {
163 // @ts-expect-error
164 window.toggleDevtools = () => setShowDevtools((old) => !old)
165 }, [])
166β
167 return (
168 <QueryClientProvider client={queryClient}>
169 <Example />
170 <ReactQueryDevtools initialIsOpen />
171 {showDevtools && (
172 <React.Suspense fallback={null}>
173 <ReactQueryDevtoolsProduction />
174 </React.Suspense>
175 )}
176 </QueryClientProvider>
177 )
178}
179β
180export default App
181```
182β
183With this, calling `window.toggleDevtools()` will download the devtools bundle and show them.
184β
185### Modern bundlers
186β
187If your bundler supports package exports, you can use the following import path:
188β
189```tsx
190const ReactQueryDevtoolsProduction = React.lazy(() =>
191 import('@tanstack/react-query-devtools/production').then((d) => ({
192 default: d.ReactQueryDevtools,
193 })),
194)
195```
196β
197For TypeScript, you would need to set `moduleResolution: 'nodenext'` in your tsconfig, which requires at least TypeScript v4.7.