Skip to content

Commit

Permalink
feat: enable toggle for react query devtools
Browse files Browse the repository at this point in the history
  • Loading branch information
brobro10000 committed May 22, 2024
1 parent 9f442ff commit 3b4a742
Showing 1 changed file with 22 additions and 2 deletions.
24 changes: 22 additions & 2 deletions src/components/App/index.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
import React, { useEffect, useMemo } from 'react';
import React, {
lazy,
Suspense,
useEffect,
useMemo,
useState,
} from 'react';
import {
Route, Navigate, Routes, generatePath, useParams,
} from 'react-router-dom';
Expand Down Expand Up @@ -28,6 +34,11 @@ import store from '../../data/store';
import { ROUTE_NAMES } from '../EnterpriseApp/data/constants';
import { defaultQueryClientRetryHandler, queryCacheOnErrorHandler } from '../../utils';

// eslint-disable-next-line import/no-unresolved
const ReactQueryDevtoolsProduction = lazy(() => import('@tanstack/react-query-devtools/production').then((d) => ({

Check warning on line 38 in src/components/App/index.jsx

View check run for this annotation

Codecov / codecov/patch

src/components/App/index.jsx#L38

Added line #L38 was not covered by tests
default: d.ReactQueryDevtools,
})));

const queryClient = new QueryClient({
queryCache: new QueryCache({
onError: queryCacheOnErrorHandler,
Expand Down Expand Up @@ -60,6 +71,11 @@ const AppWrapper = () => {
const apiClient = getAuthenticatedHttpClient();
const config = getConfig();

const [showReactQueryDevtools, setShowReactQueryDevtools] = useState(false);
useEffect(() => {
window.toggleReactQueryDevtools = () => setShowReactQueryDevtools((prevState) => !prevState);

Check warning on line 76 in src/components/App/index.jsx

View check run for this annotation

Codecov / codecov/patch

src/components/App/index.jsx#L74-L76

Added lines #L74 - L76 were not covered by tests
});

useEffect(() => {
if (process.env.HOTJAR_APP_ID) {
try {
Expand Down Expand Up @@ -90,10 +106,14 @@ const AppWrapper = () => {
}
return true;
}, [config]);

return (
<QueryClientProvider client={queryClient}>
<ReactQueryDevtools />
{showReactQueryDevtools && (
<Suspense fallback={null}>

Check warning on line 113 in src/components/App/index.jsx

View check run for this annotation

Codecov / codecov/patch

src/components/App/index.jsx#L113

Added line #L113 was not covered by tests
<ReactQueryDevtoolsProduction />
</Suspense>
)}
<AppProvider store={store}>
<Helmet
titleTemplate="%s - edX Admin Portal"
Expand Down

0 comments on commit 3b4a742

Please sign in to comment.