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