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