-
Notifications
You must be signed in to change notification settings - Fork 4
[Init] Tanstack Query 초기 세팅 #26
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 5 commits
ee7dc48
5e3b72b
abc72d0
48eeec9
a5aa996
b2fd8c3
42dd64d
5f4cb18
f5b46df
dc06439
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| import type { PropsWithChildren } from "react"; | ||
|
Check warning on line 1 in src/app/providers/QueryProvider.tsx
|
||
| import { Suspense, lazy } from "react"; | ||
| import { QueryClientProvider } from "@tanstack/react-query"; | ||
|
|
||
| import { queryClient } from "@shared/lib/react-query"; | ||
|
|
||
| const ReactQueryDevtools = import.meta.env.DEV | ||
| ? lazy(async () => { | ||
| const mod = await import("@tanstack/react-query-devtools"); | ||
| return { default: mod.ReactQueryDevtools }; | ||
| }) | ||
| : null; | ||
|
|
||
| export default function QueryProvider({ children }: PropsWithChildren) { | ||
| return ( | ||
| <QueryClientProvider client={queryClient}> | ||
| {children} | ||
|
|
||
| {import.meta.env.DEV && ReactQueryDevtools ? ( | ||
| <Suspense fallback={null}> | ||
| <ReactQueryDevtools initialIsOpen={false} /> | ||
| </Suspense> | ||
| ) : null} | ||
| </QueryClientProvider> | ||
| ); | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| import type { PropsWithChildren } from "react"; | ||
|
|
||
| import QueryProvider from "./QueryProvider"; | ||
|
|
||
| export default function AppProviders({ children }: PropsWithChildren) { | ||
| return <QueryProvider>{children}</QueryProvider>; | ||
| } | ||
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| export { queryClient } from "./queryClient"; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| import { MutationCache, QueryCache, QueryClient } from "@tanstack/react-query"; | ||
|
|
||
| export const queryClient = new QueryClient({ | ||
| defaultOptions: { | ||
| queries: { | ||
| retry: 0, | ||
| refetchOnWindowFocus: false, | ||
| refetchOnReconnect: true, | ||
|
|
||
| staleTime: 30 * 1000, | ||
| gcTime: 10 * 60 * 1000, | ||
|
|
||
| throwOnError: false, | ||
| }, | ||
| mutations: { | ||
| retry: 0, | ||
| throwOnError: false, | ||
| }, | ||
| }, | ||
|
|
||
| queryCache: new QueryCache({ | ||
| onError: (error: unknown) => { | ||
| // TODO: API 초기 세팅 PR merge 후 공통 에러 핸들러 연결 | ||
| // handleApiError(error); | ||
| console.error(error); | ||
| }, | ||
| }), | ||
|
|
||
| mutationCache: new MutationCache({ | ||
| onError: (error: unknown) => { | ||
| // TODO: API 초기 세팅 PR merge 후 공통 에러 핸들러 연결 | ||
| // handleApiError(error); | ||
| console.error(error); | ||
| }, | ||
| }), | ||
| }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
저는
query-provider로 바로 App.tsx를 감싸는 구조로 생각했는데, 여러 provider를 합성하는 역할을 수행하는AppProviders를 별도로 둔 점이 인상깊었어요.만약 다른 provider가 늘어날 경우, App.tsx가 여러 provider로 감싸지는 약간은 지저분한 구조가 되었을 것 같은데
앱 진입점을 깔끔하게 유지할 수 있는 방향이라 확장성 측면에서 너무 좋은 구조화같습니다❣️
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
index.ts에서 단순히 export만 모아주는 방식이 아닌 AppProviders로 묶어주는 구조를 처음 봐서 조금 찾아보았는데
App.tsx이 깔끔해지고 추가되는 프로바이더를 해당 파일에서만 추가하면 된다는 점에서 유지보수성이 굉장히 좋은 코드인 거 같습니다~ 하나 배워가욥~!!