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## Install and Import the Devtools
13β
14The devtools are a separate package that you need to install:
15β
16```bash
17$ npm i @tanstack/react-query-devtools
18# or
19$ pnpm add @tanstack/react-query-devtools
20# or
21$ yarn add @tanstack/react-query-devtools
22```
23β
24You can import the devtools like this:
25β
26```tsx
27import { ReactQueryDevtools } from '@tanstack/react-query-devtools'
28```
29β
30By 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.
31β
32## Floating Mode
33β
34Floating 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.
35β
36Place 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!
37β
38```tsx
39import { ReactQueryDevtools } from '@tanstack/react-query-devtools'
40β
41function App() {
42 return (
43 <QueryClientProvider client={queryClient}>
44 {/* The rest of your application */}
45 <ReactQueryDevtools initialIsOpen={false} />
46 </QueryClientProvider>
47 )
48}
49```
50β
51### Options
52β
53- `initialIsOpen: Boolean`
54 - Set this `true` if you want the dev tools to default to being open
55- `panelProps: PropsObject`
56 - Use this to add props to the panel. For example, you can add `className`, `style` (merge and override default style), etc.
57- `closeButtonProps: PropsObject`
58 - Use this to add props to the close button. For example, you can add `className`, `style` (merge and override default style), `onClick` (extend default handler), etc.
59- `toggleButtonProps: PropsObject`
60 - Use this to add props to the toggle button. For example, you can add `className`, `style` (merge and override default style), `onClick` (extend default handler), etc.
61- `position?: "top-left" | "top-right" | "bottom-left" | "bottom-right"`
62 - Defaults to `bottom-left`
63 - The position of the React Query logo to open and close the devtools panel
64- `panelPosition?: "top" | "bottom" | "left" | "right"`
65 - Defaults to `bottom`
66 - The position of the React Query devtools panel
67- `context?: React.Context<QueryClient | undefined>`
68 - Use this to use a custom React Query context. Otherwise, `defaultContext` will be used.
69β
70## Embedded Mode
71β
72Embedded Mode will embed the devtools as a regular component in your application. You can style it however you'd like after that!
73β
74```tsx
75import { ReactQueryDevtoolsPanel } from '@tanstack/react-query-devtools'
76β
77function App() {
78 return (
79 <QueryClientProvider client={queryClient}>
80 {/* The rest of your application */}
81 <ReactQueryDevtoolsPanel style={styles} className={className} />
82 </QueryClientProvider>
83 )
84}
85```
86β
87### Options
88β
89Use these options to style the dev tools.
90β
91- `style: StyleObject`
92 - The standard React style object used to style a component with inline styles
93- `className: string`
94 - The standard React className property used to style a component with classes
95- `showCloseButton?: boolean`
96 - Show a close button inside the devtools panel
97- `closeButtonProps: PropsObject`
98 - Use this to add props to the close button. For example, you can add `className`, `style` (merge and override default style), `onClick` (extend default handler), etc.
99β
100## Devtools in production
101β
102Devtools are excluded in production builds. However, it might be desirable to lazy load the devtools in production:
103β
104```tsx
105import * as React from 'react'
106import { QueryClient, QueryClientProvider } from '@tanstack/react-query'
107import { ReactQueryDevtools } from '@tanstack/react-query-devtools'
108import { Example } from './Example'
109β
110const queryClient = new QueryClient()
111β
112const ReactQueryDevtoolsProduction = React.lazy(() =>
113 import('@tanstack/react-query-devtools/build/lib/index.prod.js').then(
114 (d) => ({
115 default: d.ReactQueryDevtools,
116 }),
117 ),
118)
119β
120function App() {
121 const [showDevtools, setShowDevtools] = React.useState(false)
122β
123 React.useEffect(() => {
124 // @ts-ignore
125 window.toggleDevtools = () => setShowDevtools((old) => !old)
126 }, [])
127β
128 return (
129 <QueryClientProvider client={queryClient}>
130 <Example />
131 <ReactQueryDevtools initialIsOpen />
132 {showDevtools && (
133 <React.Suspense fallback={null}>
134 <ReactQueryDevtoolsProduction />
135 </React.Suspense>
136 )}
137 </QueryClientProvider>
138 )
139}
140β
141export default App
142```
143β
144With this, calling `window.toggleDevtools()` will download the devtools bundle and show them.
145β
146### Modern bundlers
147β
148If your bundler supports package exports, you can use the following import path:
149β
150```tsx
151const ReactQueryDevtoolsProduction = React.lazy(() =>
152 import('@tanstack/react-query-devtools/production').then((d) => ({
153 default: d.ReactQueryDevtools,
154 })),
155)
156```
157β
158For TypeScript, you would need to set `moduleResolution: 'nodenext'` in your tsconfig, which requires at least TypeScript v4.7.