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 bc01241
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions src/components/App/index.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
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 +31,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 35 in src/components/App/index.jsx

View check run for this annotation

Codecov / codecov/patch

src/components/App/index.jsx#L35

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

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

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

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

View check run for this annotation

Codecov / codecov/patch

src/components/App/index.jsx#L71-L73

Added lines #L71 - L73 were not covered by tests
});

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

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

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

View check run for this annotation

Codecov / codecov/patch

src/components/App/index.jsx#L110

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

0 comments on commit bc01241

Please sign in to comment.