Skip to content

Commit

Permalink
chore: add @tanstack/react-query-devtools (#1002)
Browse files Browse the repository at this point in the history
  • Loading branch information
dhess committed Jul 4, 2023
2 parents 47c5fd3 + 9ec6ce3 commit 2f8c185
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 1 deletion.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
"@neodrag/react": "^2.0.3",
"@orval/core": "^6.16.0",
"@tanstack/react-query": "^4.29.14",
"@tanstack/react-query-devtools": "^4.29.18",
"@types/deep-equal": "^1.0.1",
"@zxch3n/tidy": "github:hackworthltd/tidy#e07fdef2ae7bf593701817113dd47b4cd56c7a97",
"axios": "^1.4.0",
Expand Down
48 changes: 48 additions & 0 deletions pnpm-lock.yaml

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

24 changes: 23 additions & 1 deletion src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { useEffect } from "react";
import { Suspense, lazy, useEffect, useState } from "react";
import { BrowserRouter, Routes, Route, Navigate } from "react-router-dom";
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
import { ReactQueryDevtools } from "@tanstack/react-query-devtools";
import { CookiesProvider, useCookies } from "react-cookie";
import { CookieSetOptions } from "universal-cookie";
import { v4 as uuidv4 } from "uuid";
Expand All @@ -9,6 +10,14 @@ import "@/index.css";

import { ChooseSession, Edit, NoMatch } from "@/components";

const ReactQueryDevtoolsProduction = lazy(() =>
import("@tanstack/react-query-devtools/build/lib/index.prod.js").then(
(d) => ({
default: d.ReactQueryDevtools,
})
)
);

const queryClient = new QueryClient();

const idCookieOptions = (path: string): CookieSetOptions => {
Expand All @@ -24,6 +33,7 @@ const idCookieOptions = (path: string): CookieSetOptions => {

const App = (): JSX.Element => {
const [cookies, setCookie] = useCookies(["id"]);
const [showDevtools, setShowDevtools] = useState(false);

useEffect(() => {
if (!cookies.id) {
Expand All @@ -35,6 +45,12 @@ const App = (): JSX.Element => {
}
}, [cookies, setCookie]);

useEffect(() => {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
window.toggleDevtools = () => setShowDevtools((old) => !old);
}, []);

return (
<CookiesProvider>
<BrowserRouter>
Expand All @@ -47,6 +63,12 @@ const App = (): JSX.Element => {
</Route>
<Route path="*" element={<NoMatch />} />
</Routes>
<ReactQueryDevtools initialIsOpen position="top-left" />
{showDevtools && (
<Suspense fallback={null}>
<ReactQueryDevtoolsProduction position="top-left" />
</Suspense>
)}
</QueryClientProvider>
</BrowserRouter>
</CookiesProvider>
Expand Down

0 comments on commit 2f8c185

Please sign in to comment.