-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FE] feat: 꿀조합 전체 목록 조회 요청 쿼리 추가 (#449)
* feat: 꿀조합 정렬 옵션 타입 추가 * feat: 꿀조합 전체 목록 조회 목 핸들러 추가 * feat: 상품 리뷰 조회 최신순 정렬 로직 추가 * feat: 꿀조합 전체 목록 조회 쿼리 추가 * refactor: 꿀조합 목 핸들러 중복 삭제
- Loading branch information
1 parent
1db44ac
commit 7add336
Showing
8 changed files
with
107 additions
and
19 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
export { default as useRecipeDetailQuery } from './useRecipeDetailQuery'; | ||
export { default as useRecipeRegisterFormMutation } from './useRecipeRegisterFormMutation'; | ||
export { default as useInfiniteRecipesQuery } from './useInfiniteRecipesQuery'; |
24 changes: 24 additions & 0 deletions
24
frontend/src/hooks/queries/recipe/useInfiniteRecipesQuery.ts
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,24 @@ | ||
import { useInfiniteQuery } from '@tanstack/react-query'; | ||
|
||
import { recipeApi } from '@/apis'; | ||
import type { RecipeResponse } from '@/types/response'; | ||
|
||
const fetchRecipes = async (pageParam: number, sort: string) => { | ||
const response = await recipeApi.get({ queries: `?sort=${sort}&page=${pageParam}` }); | ||
const data: RecipeResponse = await response.json(); | ||
return data; | ||
}; | ||
|
||
const useInfiniteRecipesQuery = (sort: string) => { | ||
return useInfiniteQuery({ | ||
queryKey: ['recipe', sort], | ||
queryFn: ({ pageParam = 0 }) => fetchRecipes(pageParam, sort), | ||
getNextPageParam: (prevResponse: RecipeResponse) => { | ||
const isLast = prevResponse.page.lastPage; | ||
const nextPage = prevResponse.page.requestPage + 1; | ||
return isLast ? undefined : nextPage; | ||
}, | ||
}); | ||
}; | ||
|
||
export default useInfiniteRecipesQuery; |
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