Skip to content

Commit 3c86001

Browse files
committed
feat: add react-query
1 parent 0259683 commit 3c86001

File tree

6 files changed

+81
-13
lines changed

6 files changed

+81
-13
lines changed

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
"coverage": "vitest run --coverage"
1313
},
1414
"dependencies": {
15+
"@tanstack/react-query": "^5.85.2",
16+
"@tanstack/react-query-devtools": "^5.85.2",
1517
"react": "^19.1.1",
1618
"react-dom": "^19.1.1",
1719
"react-router": "^7.8.0"

pnpm-lock.yaml

Lines changed: 41 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/apps/app/app.tsx

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,21 @@
1-
import { BrowserRouter as Router } from 'react-router-dom';
1+
import { RouterProvider } from 'react-router-dom';
22
import { DialogPortal } from '@/shared/utils';
3-
import { AppRoutes } from './routes';
3+
import { router } from './routes';
4+
import { ReactQueryProvider } from './providers';
45
import { Header } from '@/widgets/header';
56
import { Footer } from '@/widgets/footer';
67

78
export function App() {
89
return (
9-
<Router>
10+
<ReactQueryProvider>
1011
<div className='flex flex-col min-h-screen'>
1112
<Header />
1213
<main className='flex-grow container mx-auto px-4 py-8'>
13-
<AppRoutes />
14+
<RouterProvider router={router} />
1415
</main>
1516
<Footer />
1617
</div>
1718
<DialogPortal />
18-
</Router>
19+
</ReactQueryProvider>
1920
);
2021
}

src/apps/app/providers/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from './react-query';
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import { useState, type PropsWithChildren } from 'react';
2+
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
3+
import { ReactQueryDevtools } from '@tanstack/react-query-devtools';
4+
5+
export function ReactQueryProvider({ children }: PropsWithChildren) {
6+
const [queryClient] = useState(
7+
() =>
8+
new QueryClient({
9+
defaultOptions: {
10+
queries: {
11+
refetchOnWindowFocus: false,
12+
retry: 1,
13+
},
14+
},
15+
}),
16+
);
17+
18+
return (
19+
<QueryClientProvider client={queryClient}>
20+
{children}
21+
<ReactQueryDevtools initialIsOpen={false} buttonPosition='bottom-right' />
22+
</QueryClientProvider>
23+
);
24+
}

src/apps/app/routes.tsx

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
1-
import { Routes, Route } from 'react-router-dom';
1+
import { createBrowserRouter } from 'react-router-dom';
22
import { PostsManagerPage } from '@/pages/home';
33

4-
export function AppRoutes() {
5-
return (
6-
<Routes>
7-
<Route path='/' element={<PostsManagerPage />} />
8-
</Routes>
9-
);
10-
}
4+
export const router = createBrowserRouter([
5+
{
6+
path: '/',
7+
element: <PostsManagerPage />,
8+
},
9+
]);

0 commit comments

Comments
 (0)