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
23$ npm i @tanstack/react-query-devtools
24# or
25$ pnpm add @tanstack/react-query-devtools
26# or
27$ yarn add @tanstack/react-query-devtools
28# or
29$ bun add @tanstack/react-query-devtools
30```
31β
32For Next 13+ App Dir you must install it as a dev dependency for it to work.
33β
34You can import the devtools like this:
35β
36```tsx
37import { ReactQueryDevtools } from '@tanstack/react-query-devtools'
38```
39β
40By 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.
41β
42## Floating Mode
43β
44Floating 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.
45β
46Place 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!
47β
48```tsx
49import { ReactQueryDevtools } from '@tanstack/react-query-devtools'
50β
51function App() {
52 return (
53 <QueryClientProvider client={queryClient}>
54 {/* The rest of your application */}
55 <ReactQueryDevtools initialIsOpen={false} />
56 </QueryClientProvider>
57 )
58}
59```
60β
61### Options
62β
63- `initialIsOpen: Boolean`
64 - Set this `true` if you want the dev tools to default to being open
65- `buttonPosition?: "top-left" | "top-right" | "bottom-left" | "bottom-right" | "relative"`
66 - Defaults to `bottom-right`
67 - The position of the React Query logo to open and close the devtools panel
68 - If `relative`, the button is placed in the location that you render the devtools.
69- `position?: "top" | "bottom" | "left" | "right"`
70 - Defaults to `bottom`
71 - The position of the React Query devtools panel
72- `client?: QueryClient`,
73 - Use this to use a custom QueryClient. Otherwise, the one from the nearest context will be used.
74- `errorTypes?: { name: string; initializer: (query: Query) => TError}`
75 - 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.
76- `styleNonce?: string`
77 - 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.
78- `shadowDOMTarget?: ShadowRoot`
79 - Default behavior will apply the devtool's styles to the head tag within the DOM.
80 - 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.
81β
82## Devtools in production
83β
84Devtools are excluded in production builds. However, it might be desirable to lazy load the devtools in production:
85β
86```tsx
87import * as React from 'react'
88import { QueryClient, QueryClientProvider } from '@tanstack/react-query'
89import { ReactQueryDevtools } from '@tanstack/react-query-devtools'
90import { Example } from './Example'
91β
92const queryClient = new QueryClient()
93β
94const ReactQueryDevtoolsProduction = React.lazy(() =>
95 import('@tanstack/react-query-devtools/build/modern/production.js').then(
96 (d) => ({
97 default: d.ReactQueryDevtools,
98 }),
99 ),
100)
101β
102function App() {
103 const [showDevtools, setShowDevtools] = React.useState(false)
104β
105 React.useEffect(() => {
106 // @ts-expect-error
107 window.toggleDevtools = () => setShowDevtools((old) => !old)
108 }, [])
109β
110 return (
111 <QueryClientProvider client={queryClient}>
112 <Example />
113 <ReactQueryDevtools initialIsOpen />
114 {showDevtools && (
115 <React.Suspense fallback={null}>
116 <ReactQueryDevtoolsProduction />
117 </React.Suspense>
118 )}
119 </QueryClientProvider>
120 )
121}
122β
123export default App
124```
125β
126With this, calling `window.toggleDevtools()` will download the devtools bundle and show them.
127β
128### Modern bundlers
129β
130If your bundler supports package exports, you can use the following import path:
131β
132```tsx
133const ReactQueryDevtoolsProduction = React.lazy(() =>
134 import('@tanstack/react-query-devtools/production').then((d) => ({
135 default: d.ReactQueryDevtools,
136 })),
137)
138```
139β
140For TypeScript, you would need to set `moduleResolution: 'nodenext'` in your tsconfig, which requires at least TypeScript v4.7.