Skip to content

Commit

Permalink
[Feature/BAR-7] @tanstack/react-query 설정 (#11)
Browse files Browse the repository at this point in the history
* feat: @tanstack/react-query 설정

* feat: @tanstack/eslint-plugin-query 설정

* fix: 세미콜론 제거
  • Loading branch information
dmswl98 authored Dec 19, 2023
1 parent cfcdd6c commit 8ec5ab7
Show file tree
Hide file tree
Showing 5 changed files with 82 additions and 4 deletions.
3 changes: 2 additions & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
"prettier",
"eslint:recommended",
"plugin:react-hooks/recommended",
"plugin:jsx-a11y/recommended"
"plugin:jsx-a11y/recommended",
"plugin:@tanstack/eslint-plugin-query/recommended"
],
"parser": "@typescript-eslint/parser",
"plugins": [
Expand Down
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@
"@storybook/nextjs": "^7.6.4",
"@storybook/react": "^7.6.4",
"@storybook/test": "^7.6.4",
"@tanstack/eslint-plugin-query": "^5.12.1",
"@tanstack/react-query-devtools": "^5.14.1",
"@types/node": "^20",
"@types/react": "^18",
"@types/react-dom": "^18",
Expand Down
8 changes: 7 additions & 1 deletion pages/_app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,14 @@ import type { AppProps } from 'next/app';

import '@/src/styles/global.css';

import TanstackQueryProvider from '@/src/components/Providers/TanstackQueryProvider';

const App = ({ Component, pageProps }: AppProps) => {
return <Component {...pageProps} />;
return (
<TanstackQueryProvider dehydratedState={pageProps.dehydratedState}>
<Component {...pageProps} />
</TanstackQueryProvider>
);
};

export default App;
35 changes: 33 additions & 2 deletions pnpm-lock.yaml

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

38 changes: 38 additions & 0 deletions src/components/Providers/TanstackQueryProvider.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { type PropsWithChildren, useState } from 'react';

import {
type DehydratedState,
HydrationBoundary,
QueryClient,
QueryClientProvider,
} from '@tanstack/react-query';
import { ReactQueryDevtools } from '@tanstack/react-query-devtools';

interface TanstackQueryProviderProps {
dehydratedState: DehydratedState;
}

const TanstackQueryProvider = ({
children,
dehydratedState,
}: PropsWithChildren<TanstackQueryProviderProps>) => {
const [queryClient] = useState(
() =>
new QueryClient({
defaultOptions: {
queries: {
refetchOnWindowFocus: false,
},
},
}),
);

return (
<QueryClientProvider client={queryClient}>
<HydrationBoundary state={dehydratedState}>{children}</HydrationBoundary>
<ReactQueryDevtools />
</QueryClientProvider>
);
};

export default TanstackQueryProvider;

0 comments on commit 8ec5ab7

Please sign in to comment.