Skip to content

Commit 6113031

Browse files
committed
refactor: 게시글 상세 정보 조회 api를 감싸는 react-query 생성
1 parent 86cb993 commit 6113031

1 file changed

Lines changed: 10 additions & 0 deletions

File tree

src/apis/post/index.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { useQuery } from '@tanstack/react-query';
2+
13
import { newRequest } from '@apis/core';
24

35
import type { EmptySuccessResponse } from '@apis/core/dto';
@@ -36,3 +38,11 @@ export const deletePostApi = (postId: number) => newRequest.delete<EmptySuccessR
3638
// 대표 게시글 지정
3739
export const modifyPostRepresentativeStatusApi = (postId: number) =>
3840
newRequest.patch<EmptySuccessResponse>(`/post/${postId}/is-representative`);
41+
42+
export const usePostDetail = (postId: number) => {
43+
return useQuery({
44+
queryKey: ['postDetail', postId],
45+
queryFn: () => getPostDetailApi(postId),
46+
enabled: !!postId, // postId가 존재할 때만 요청 수행
47+
});
48+
};

0 commit comments

Comments
 (0)