-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Navbar형식 수정 + RSC 방식 query-string 라우팅 도입
Navbar형식 수정 + RSC 방식 query-string 라우팅 도입
- Loading branch information
Showing
6 changed files
with
156 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import { useInfiniteQuery } from '@tanstack/react-query'; | ||
import axios from 'axios'; | ||
import { lastDayOfDecade } from 'date-fns'; | ||
|
||
const fetchNoticeLists = async ({ | ||
queryKey, | ||
pageParam = 1 | ||
}: { | ||
queryKey: string[]; | ||
pageParam: number; | ||
}) => { | ||
const [, category] = queryKey; | ||
const { data } = await axios.get( | ||
`https://api.moaguide.com/detail/notice/list/${category}?page=${pageParam}&size=10` | ||
); | ||
return data; | ||
}; | ||
|
||
const UseNoticeLists = (category: string) => { | ||
const queryKey = ['NoticeLists', category]; | ||
|
||
const { data, fetchNextPage, hasNextPage, isFetching, isFetchingNextPage, isLoading } = | ||
useInfiniteQuery({ | ||
queryKey, | ||
queryFn: fetchNoticeLists, | ||
getNextPageParam: (lastPage, allPages) => { | ||
if (lastPage.length === 0) { | ||
return undefined; | ||
} | ||
return allPages.length + 1; | ||
}, | ||
initialPageParam: 1, | ||
enabled: !!category | ||
}); | ||
|
||
return { | ||
data, | ||
fetchNextPage, | ||
hasNextPage: !!data?.pages.length, | ||
isFetching, | ||
isFetchingNextPage, | ||
isLoading | ||
}; | ||
}; | ||
|
||
export default UseNoticeLists; |