Skip to content

Commit

Permalink
feat: (#275) 게시물 상세 컴포넌트에서 게시글 정보 불러오기 리액트 쿼리 도입
Browse files Browse the repository at this point in the history
  • Loading branch information
chsua committed Aug 9, 2023
1 parent 726ee59 commit 16a6983
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
4 changes: 2 additions & 2 deletions frontend/src/hooks/query/post/usePostDetail.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { getPost } from '@api/post';
import { QUERY_KEY } from '@constants/queryKey';

export const usePostDetail = (postId: number) => {
const { data, error, isLoading } = useQuery<PostInfo>(
const { data, isError, isLoading } = useQuery<PostInfo>(
[QUERY_KEY.POST_DETAIL, postId],
() => getPost(postId),
{
Expand All @@ -20,5 +20,5 @@ export const usePostDetail = (postId: number) => {
}
);

return { data, error, isLoading };
return { data, isError, isLoading };
};
10 changes: 5 additions & 5 deletions frontend/src/pages/post/PostDetail/index.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { useNavigate, useParams } from 'react-router-dom';

import { useCommentList } from '@hooks/query/comment/useCommentList';
import { useFetch } from '@hooks/useFetch';
import { usePostDetail } from '@hooks/query/post/usePostDetail';

import { getPost, removePost, setEarlyClosePost } from '@api/post';
import { removePost, setEarlyClosePost } from '@api/post';

import CommentList from '@components/comment/CommentList';
import Layout from '@components/common/Layout';
Expand All @@ -27,7 +27,8 @@ export default function PostDetailPage() {
const decodedPayload = getMemberId(token);
const memberId = decodedPayload.memberId;

const { data: postData, errorMessage, isLoading, refetch } = useFetch(() => getPost(postId));
const { data: postData, isError, isLoading } = usePostDetail(postId);
// const { data: postData, errorMessage, isLoading, refetch } = useFetch(() => getPost(postId));
const { data: commentData, isLoading: isCommentLoading } = useCommentList(postId);
// const { data: userInfo, isLoading: isUserInfoLoading, error } = useUserInfo(isLoggedIn);

Expand All @@ -41,7 +42,7 @@ export default function PostDetailPage() {
</S.HeaderContainer>
<S.Container>
{isLoading && 'loading'}
{errorMessage && errorMessage}
{isError && 'error발생'}
</S.Container>
</Layout>
);
Expand Down Expand Up @@ -73,7 +74,6 @@ export default function PostDetailPage() {
await setEarlyClosePost(postId)
.then(res => {
alert('게시물을 즉시마감했습니다.');
refetch();
})
.catch(error => alert(error.message));
},
Expand Down

0 comments on commit 16a6983

Please sign in to comment.