Skip to content

Commit 20dff2a

Browse files
authored
added react query dev tools (#11293)
1 parent 19e4a86 commit 20dff2a

File tree

3 files changed

+67
-1
lines changed

3 files changed

+67
-1
lines changed

site/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
"@mui/material": "5.14.0",
4343
"@mui/system": "5.14.0",
4444
"@mui/utils": "5.14.11",
45+
"@tanstack/react-query-devtools": "4.35.3",
4546
"@vitejs/plugin-react": "4.1.0",
4647
"ansi-to-html": "0.7.2",
4748
"axios": "1.6.0",

site/pnpm-lock.yaml

Lines changed: 48 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

site/src/App.tsx

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
import { QueryClient, QueryClientProvider } from "react-query";
2-
import type { FC, ReactNode } from "react";
2+
import { type FC, type ReactNode, useEffect, useState } from "react";
33
import { HelmetProvider } from "react-helmet-async";
44
import { AppRouter } from "./AppRouter";
55
import { ThemeProvider } from "./contexts/ThemeProvider";
66
import { AuthProvider } from "./contexts/AuthProvider/AuthProvider";
77
import { ErrorBoundary } from "./components/ErrorBoundary/ErrorBoundary";
88
import { GlobalSnackbar } from "./components/GlobalSnackbar/GlobalSnackbar";
99
import "./theme/globalFonts";
10+
import { ReactQueryDevtools } from "@tanstack/react-query-devtools";
1011

1112
const defaultQueryClient = new QueryClient({
1213
defaultOptions: {
@@ -22,10 +23,25 @@ interface AppProvidersProps {
2223
queryClient?: QueryClient;
2324
}
2425

26+
// extending the global window interface so we can conditionally
27+
// show our react query devtools
28+
declare global {
29+
interface Window {
30+
toggleDevtools: () => void;
31+
}
32+
}
33+
2534
export const AppProviders: FC<AppProvidersProps> = ({
2635
children,
2736
queryClient = defaultQueryClient,
2837
}) => {
38+
// https://tanstack.com/query/v4/docs/react/devtools
39+
const [showDevtools, setShowDevtools] = useState(false);
40+
useEffect(() => {
41+
window.toggleDevtools = () => setShowDevtools((old) => !old);
42+
// eslint-disable-next-line react-hooks/exhaustive-deps -- no dependencies needed here
43+
}, []);
44+
2945
return (
3046
<HelmetProvider>
3147
<QueryClientProvider client={queryClient}>
@@ -35,6 +51,7 @@ export const AppProviders: FC<AppProvidersProps> = ({
3551
<GlobalSnackbar />
3652
</ThemeProvider>
3753
</AuthProvider>
54+
{showDevtools && <ReactQueryDevtools initialIsOpen={showDevtools} />}
3855
</QueryClientProvider>
3956
</HelmetProvider>
4057
);

0 commit comments

Comments
 (0)