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