Skip to content
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

feat: enable toggle for react query devtools #1233

Merged
merged 3 commits into from
May 22, 2024
Merged
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
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 { 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 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 @@
}
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
Loading