-
Notifications
You must be signed in to change notification settings - Fork 1
Refactor(client): loading error boundary 적용 #214
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
2e88501
e942b45
ebae55e
c7e442a
6cbc7f3
4e7e714
877ea28
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,53 +1,46 @@ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import { useInfiniteQuery } from '@tanstack/react-query'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import { useSuspenseInfiniteQuery } from '@tanstack/react-query'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| getBookmarkArticles, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| getBookmarkUnreadArticles, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| getCategoryBookmarkArticles, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } from './axios'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| export const useGetBookmarkArticles = () => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return useInfiniteQuery({ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return useSuspenseInfiniteQuery({ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| queryKey: ['bookmarkReadArticles'], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| queryFn: ({ pageParam = 0 }) => getBookmarkArticles(pageParam, 20), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| initialPageParam: 0, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| getNextPageParam: (lastPage, allPages) => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (lastPage.articles.length === 0) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return undefined; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return allPages.length; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| getNextPageParam: (lastPage, allPages) => | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| lastPage.articles.length === 0 ? undefined : allPages.length, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| export const useGetBookmarkUnreadArticles = () => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return useInfiniteQuery({ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return useSuspenseInfiniteQuery({ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| queryKey: ['bookmarkUnreadArticles'], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| queryFn: ({ pageParam = 0 }) => getBookmarkUnreadArticles(pageParam, 20), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| initialPageParam: 0, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| getNextPageParam: (lastPage, allPages) => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (lastPage.articles.length === 0) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return undefined; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return allPages.length; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| getNextPageParam: (lastPage, allPages) => | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| lastPage.articles.length === 0 ? undefined : allPages.length, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| export const useGetCategoryBookmarkArticles = ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| categoryId: string | null, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| readStatus: boolean | null | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ) => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return useInfiniteQuery({ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return useSuspenseInfiniteQuery({ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| queryKey: ['categoryBookmarkArticles', readStatus, categoryId], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| queryFn: ({ pageParam = 0 }) => | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| getCategoryBookmarkArticles(categoryId, readStatus, pageParam, 20), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| queryFn: ({ pageParam = 0 }) => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (!categoryId) return null; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return getCategoryBookmarkArticles(categoryId, readStatus, pageParam, 20); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| initialPageParam: 0, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| getNextPageParam: (lastPage, allPages) => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (lastPage.articles.length === 0) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return undefined; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (!lastPage || lastPage.articles.length === 0) return undefined; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return allPages.length; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| enabled: !!categoryId, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+32
to
45
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.
TypeScript 사용자는 현재 코드에서 +import { useSuspenseInfiniteQuery, skipToken } from '@tanstack/react-query';
export const useGetCategoryBookmarkArticles = (
categoryId: string | null,
readStatus: boolean | null
) => {
return useSuspenseInfiniteQuery({
queryKey: ['categoryBookmarkArticles', readStatus, categoryId],
- queryFn: ({ pageParam = 0 }) => {
- if (!categoryId) return null;
- return getCategoryBookmarkArticles(categoryId, readStatus, pageParam, 20);
- },
+ queryFn: categoryId
+ ? ({ pageParam = 0 }) =>
+ getCategoryBookmarkArticles(categoryId, readStatus, pageParam, 20)
+ : skipToken,
initialPageParam: 0,
getNextPageParam: (lastPage, allPages) => {
- if (!lastPage || lastPage.articles.length === 0) return undefined;
+ if (lastPage.articles.length === 0) return undefined;
return allPages.length;
},
});
};📝 Committable suggestion
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
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.
suspenseInfiniteQuery는 진심으로 처음 봤는데,, tanstack이 지원해주는게 참 많구만요