Skip to content

Commit

Permalink
chore: add cache for react query
Browse files Browse the repository at this point in the history
  • Loading branch information
mari1912 committed Jul 19, 2024
1 parent d77eb43 commit 6bbd34d
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 5 deletions.
4 changes: 3 additions & 1 deletion dashboard/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,18 @@
"@emotion/styled": "^11.11.5",
"@mui/material": "^5.15.20",
"@mui/x-charts": "^7.7.1",
"@radix-ui/react-collapsible": "^1.1.0",
"@radix-ui/react-checkbox": "^1.1.1",
"@radix-ui/react-collapsible": "^1.1.0",
"@radix-ui/react-dialog": "^1.1.1",
"@radix-ui/react-dropdown-menu": "^2.1.1",
"@radix-ui/react-label": "^2.1.0",
"@radix-ui/react-navigation-menu": "^1.2.0",
"@radix-ui/react-separator": "^1.1.0",
"@radix-ui/react-slot": "^1.1.0",
"@radix-ui/react-tabs": "^1.1.0",
"@tanstack/query-sync-storage-persister": "^5.51.9",
"@tanstack/react-query": "^5.45.1",
"@tanstack/react-query-persist-client": "^5.51.9",
"@tanstack/react-table": "^8.17.3",
"@vitejs/plugin-react": "^4.3.1",
"axios": "^1.7.2",
Expand Down
38 changes: 38 additions & 0 deletions dashboard/pnpm-lock.yaml

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

28 changes: 24 additions & 4 deletions dashboard/src/main.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
import React from 'react';
import ReactDOM from 'react-dom/client';
import { RouterProvider, createBrowserRouter } from 'react-router-dom';
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
import { QueryClient } from '@tanstack/react-query';

import { IntlProvider } from 'react-intl';

import { flatten } from 'flat';

import { PersistQueryClientProvider } from '@tanstack/react-query-persist-client';

import { createSyncStoragePersister } from '@tanstack/query-sync-storage-persister';

import { messages } from './locales/messages/index';
import { LOCALES } from './locales/constants';

Expand All @@ -15,7 +19,20 @@ import Root from './routes/Root/Root';
import Trees from './routes/Trees/Trees';
import TreeDetails from './routes/TreeDetails/TreeDetails';

const queryClient = new QueryClient();
const queryClient = new QueryClient({
defaultOptions: {
queries: {
// eslint-disable-next-line no-magic-numbers
gcTime: 1000 * 60 * 30, // 30 minutes,
// eslint-disable-next-line no-magic-numbers
staleTime: 1000 * 60 * 30, // 30 minutes,
},
},
});

const persister = createSyncStoragePersister({
storage: window.localStorage,
});

const router = createBrowserRouter([
{
Expand All @@ -36,10 +53,13 @@ const router = createBrowserRouter([

ReactDOM.createRoot(document.getElementById('root')!).render(
<React.StrictMode>
<QueryClientProvider client={queryClient}>
<PersistQueryClientProvider
client={queryClient}
persistOptions={{ persister }}
>
<IntlProvider messages={flatten(messages[LOCALES.EN_US])} locale="en">
<RouterProvider router={router} />
</IntlProvider>
</QueryClientProvider>
</PersistQueryClientProvider>
</React.StrictMode>,
);

0 comments on commit 6bbd34d

Please sign in to comment.