Skip to content

Commit

Permalink
feat: enable toggle for react query devtools (#1233)
Browse files Browse the repository at this point in the history
* feat: enable toggle for react query devtools

* chore: PR feedback
  • Loading branch information
brobro10000 committed May 22, 2024
1 parent 5a3982c commit f3ee5ea
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) => ({
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);
});

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}>
<ReactQueryDevtoolsProduction />
</Suspense>
)}
<AppProvider store={store}>
<Helmet
titleTemplate="%s - edX Admin Portal"
Expand Down

0 comments on commit f3ee5ea

Please sign in to comment.