Thanks to visit codestin.com
Credit goes to github.com

Skip to content

chore(site): add react query dev tools #11293

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions site/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
"@mui/material": "5.14.0",
"@mui/system": "5.14.0",
"@mui/utils": "5.14.11",
"@tanstack/react-query-devtools": "4.35.3",
"@vitejs/plugin-react": "4.1.0",
"ansi-to-html": "0.7.2",
"axios": "1.6.0",
Expand Down
48 changes: 48 additions & 0 deletions site/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 18 additions & 1 deletion site/src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import { QueryClient, QueryClientProvider } from "react-query";
import type { FC, ReactNode } from "react";
import { type FC, type ReactNode, useEffect, useState } from "react";
import { HelmetProvider } from "react-helmet-async";
import { AppRouter } from "./AppRouter";
import { ThemeProvider } from "./contexts/ThemeProvider";
import { AuthProvider } from "./contexts/AuthProvider/AuthProvider";
import { ErrorBoundary } from "./components/ErrorBoundary/ErrorBoundary";
import { GlobalSnackbar } from "./components/GlobalSnackbar/GlobalSnackbar";
import "./theme/globalFonts";
import { ReactQueryDevtools } from "@tanstack/react-query-devtools";

const defaultQueryClient = new QueryClient({
defaultOptions: {
Expand All @@ -22,10 +23,25 @@ interface AppProvidersProps {
queryClient?: QueryClient;
}

// extending the global window interface so we can conditionally
// show our react query devtools
declare global {
interface Window {
toggleDevtools: () => void;
}
}

export const AppProviders: FC<AppProvidersProps> = ({
children,
queryClient = defaultQueryClient,
}) => {
// https://tanstack.com/query/v4/docs/react/devtools
const [showDevtools, setShowDevtools] = useState(false);
useEffect(() => {
window.toggleDevtools = () => setShowDevtools((old) => !old);
// eslint-disable-next-line react-hooks/exhaustive-deps -- no dependencies needed here
}, []);

return (
<HelmetProvider>
<QueryClientProvider client={queryClient}>
Expand All @@ -35,6 +51,7 @@ export const AppProviders: FC<AppProvidersProps> = ({
<GlobalSnackbar />
</ThemeProvider>
</AuthProvider>
{showDevtools && <ReactQueryDevtools initialIsOpen={showDevtools} />}
</QueryClientProvider>
</HelmetProvider>
);
Expand Down