Skip to content

Commit

Permalink
feat: 데이터 가공 query쪽에서 하도록
Browse files Browse the repository at this point in the history
  • Loading branch information
shinhyojeong committed Jan 12, 2024
1 parent 76e1d11 commit c60ab55
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
10 changes: 9 additions & 1 deletion src/apis/post/queries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,15 @@ export const useCreatePostMutation = () =>
export const useGetPostQuery = (id: number) =>
useQuery({
queryKey: ['getPost', id],
queryFn: () => getPost(id)
queryFn: () => getPost(id),
select: data => ({
...data,
postImages:
data.imageUrls.map((url, idx) => ({
id: idx,
src: url
})) || []
})
})

export const useGetCategoriesQuery = () =>
Expand Down
8 changes: 2 additions & 6 deletions src/pages/post/[postId]/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,18 +32,14 @@ const PostDetailPage = ({ postId }: Props): ReactElement => {
const imageModal = useModal()

const isSeller = user.id === postQuery.data?.seller.id
const postImages =
postQuery.data?.imageUrls.map((url, idx) => ({
id: idx,
src: url
})) || []
const postImages = postQuery.data?.postImages || []

return (
<>
<Layout>
<Main>
<div onClick={imageModal.openModal}>
<Carousel images={postImages || []} isArrow name="post-carousel" />
<Carousel images={postImages} isArrow name="post-carousel" />
</div>
<Content>
<div>
Expand Down

0 comments on commit c60ab55

Please sign in to comment.