-
Notifications
You must be signed in to change notification settings - Fork 1
[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 all 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,7 @@ | ||
| import type { PropsWithChildren } from "react"; | ||
|
|
||
| import QueryProvider from "./query-provider"; | ||
|
|
||
| export default function AppProviders({ children }: PropsWithChildren) { | ||
| return <QueryProvider>{children}</QueryProvider>; | ||
| } | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Comfit은 컴포넌트 명칭은
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 아우~꼼꼼해😍 |
| 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/query-provider.tsx
|
||
| import { Suspense, lazy } from "react"; | ||
| import { QueryClientProvider } from "@tanstack/react-query"; | ||
|
|
||
| import { queryClient } from "@/shared/api"; | ||
|
|
||
| const ReactQueryDevtools = import.meta.env.DEV | ||
| ? lazy(async () => { | ||
| const mod = await import("@tanstack/react-query-devtools"); | ||
| return { default: mod.ReactQueryDevtools }; | ||
| }) | ||
| : null; | ||
|
Comment on lines
+7
to
+12
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 단순히 |
||
|
|
||
| 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 @@ | ||
| export { queryClient } from "./query-client"; |
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 작성해주신 구조가 📂 src
└─📂 shared
└─📂 api
└─📄 query-client.ts한 번 고려해주시면 좋을 부분 같아요!
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 저도 수빈님의 의견에 동의합니다! 유틸함수가 아닌 것은 아니지만 api를 위한 파일이라는 명확한 목적이 있기 때문에 api 폴더에 넣어두면 충분할 거 같아요 |
| 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 후 공통 에러 핸들러 연결 | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. TODO로 추후에 필요한 작업 정리해둔 점 아주 굿~ |
||
| // 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이 깔끔해지고 추가되는 프로바이더를 해당 파일에서만 추가하면 된다는 점에서 유지보수성이 굉장히 좋은 코드인 거 같습니다~ 하나 배워가욥~!!