Skip to content

Commit ff35d65

Browse files
committed
feat: add QueryProvider and related configurations for React Query integration
1 parent 318e581 commit ff35d65

File tree

12 files changed

+112
-582
lines changed

12 files changed

+112
-582
lines changed

eslint.config.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import pluginJs from '@eslint/js';
1111
import stylisticPlugin from '@stylistic/eslint-plugin';
1212
import stylisticPluginMigrate from '@stylistic/eslint-plugin-migrate';
13+
import pluginQuery from '@tanstack/eslint-plugin-query';
1314
import pluginRouter from '@tanstack/eslint-plugin-router';
1415
import tsParser from '@typescript-eslint/parser';
1516
import importPlugin from 'eslint-plugin-import';
@@ -39,6 +40,7 @@ export default [
3940
reactPlugin.configs.flat['jsx-runtime'],
4041
pluginLingui.configs['flat/recommended'],
4142
...pluginRouter.configs['flat/recommended'],
43+
...pluginQuery.configs['flat/recommended'],
4244
{
4345
files: ['**/*.{js,mjs,cjs,jsx,mjsx,ts,tsx,mtsx}'],
4446
languageOptions: {

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@
4242
"@mantine/hooks": "^7.15.2",
4343
"@mantine/modals": "^7.15.2",
4444
"@mantine/notifications": "^7.15.2",
45+
"@tanstack/react-query": "^5.62.15",
46+
"@tanstack/react-query-devtools": "^5.62.15",
4547
"concurrently": "^9.1.0",
4648
"dayjs": "^1.11.13",
4749
"lucide-react": "^0.469.0",
@@ -58,6 +60,7 @@
5860
"@stylistic/eslint-plugin": "^2.12.1",
5961
"@stylistic/eslint-plugin-migrate": "^2.12.1",
6062
"@swc/jest": "^0.2.37",
63+
"@tanstack/eslint-plugin-query": "^5.62.15",
6164
"@tanstack/eslint-plugin-router": "^1.87.6",
6265
"@tanstack/react-router": "^1.92.3",
6366
"@tanstack/router-devtools": "^1.92.3",
@@ -76,7 +79,6 @@
7679
"core-js": "^3.39.0",
7780
"cz-customizable": "^7.4.0",
7881
"eslint": "^9.17.0",
79-
"eslint-config-react-app": "^7.0.1",
8082
"eslint-import-resolver-typescript": "^3.7.0",
8183
"eslint-plugin-import": "^2.31.0",
8284
"eslint-plugin-import-newlines": "^1.4.0",

pnpm-lock.yaml

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

src/configs/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1+
export * from './query-client.config';
12
export * from './theme.config';

src/configs/query-client.config.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { QueryClient } from '@tanstack/react-query';
2+
3+
export const client = new QueryClient({
4+
defaultOptions: {
5+
queries: {
6+
refetchOnWindowFocus: false,
7+
},
8+
},
9+
});

src/main.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { createRouter,RouterProvider } from '@tanstack/react-router';
22
import { StrictMode } from 'react';
33
import { createRoot } from 'react-dom/client';
44

5-
import { IntlProvider, ThemeProvider } from './providers';
5+
import { IntlProvider, QueryProvider, ThemeProvider } from './providers';
66
import { routeTree } from './route-tree.gen';
77

88
const router = createRouter({
@@ -24,7 +24,9 @@ if (!rootElement.innerHTML) {
2424
<StrictMode>
2525
<IntlProvider locale="en">
2626
<ThemeProvider>
27-
<RouterProvider router={router} />
27+
<QueryProvider>
28+
<RouterProvider router={router} />
29+
</QueryProvider>
2830
</ThemeProvider>
2931
</IntlProvider>
3032
</StrictMode>,

src/providers/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
export * from './intl';
2+
export * from './query';
23
export * from './theme';

src/providers/query/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from './query.provider';
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { renderWrapper, screen } from '@/tests';
2+
3+
describe('QueryProvider Component', () => {
4+
it('should render children', async () => {
5+
renderWrapper(
6+
<div>Children of Theme Provider</div>,
7+
);
8+
9+
expect(screen.getByText('Children of Theme Provider')).toBeInTheDocument();
10+
});
11+
});
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import { QueryClientProvider } from '@tanstack/react-query';
2+
import { ReactQueryDevtools } from '@tanstack/react-query-devtools';
3+
import type { PropsWithChildren } from 'react';
4+
5+
import { client } from '@/configs';
6+
7+
export const QueryProvider = ({ children }: PropsWithChildren) => {
8+
return (
9+
<QueryClientProvider client={client}>
10+
{children}
11+
<ReactQueryDevtools
12+
buttonPosition="bottom-left"
13+
initialIsOpen={false}
14+
/>
15+
</QueryClientProvider>
16+
);
17+
};

0 commit comments

Comments
 (0)