diff --git a/src/Apis/Notices/index.ts b/src/Apis/Notices/index.ts index e49031c..c7d4955 100644 --- a/src/Apis/Notices/index.ts +++ b/src/Apis/Notices/index.ts @@ -66,11 +66,14 @@ export const useNoticeDetailData = (noticeId: string) => { title: data.title, content: data.content, created_at: new Date(data.created_at).toISOString(), - attachments: data.attachments.map((attachment: any) => ({ - url: attachment.url, - type: attachment.type, - })), + attachments: data.attachments + ? data.attachments.map((attachment: any) => ({ + url: attachment.url, + type: attachment.type, + })) + : [], }; + setNoticeDetail(fetchedNoticeDetail); }) .catch(() => { @@ -120,7 +123,6 @@ export const useNoticeListData = () => { useEffect(() => { fetchNoticeList(); - }, [fetchNoticeList]); return { notices }; diff --git a/src/Apis/Notices/response.ts b/src/Apis/Notices/response.ts index 56d2e55..cb53453 100644 --- a/src/Apis/Notices/response.ts +++ b/src/Apis/Notices/response.ts @@ -1,21 +1,19 @@ export interface NoticeListResponse { - id: number - title: string - created_at: string + id: number; + title: string; + created_at: string; } export interface NoticeDetailResponse { - title: string; - content: string; - created_at: string; - attachments?: AttachmentResponse[]; + title: string; + content: string; + created_at: string; + attachments?: AttachmentResponse[] | null; } -export type AttachmentType = - | "FILE" - | "URL" +export type AttachmentType = 'FILE' | 'URL'; export interface AttachmentResponse { - url: string; - type: AttachmentType; -} \ No newline at end of file + url: string; + type: AttachmentType; +} diff --git a/src/Components/Notice/AttachedBox/index.tsx b/src/Components/Notice/AttachedBox/index.tsx index 54f9c5a..1c3e759 100644 --- a/src/Components/Notice/AttachedBox/index.tsx +++ b/src/Components/Notice/AttachedBox/index.tsx @@ -4,7 +4,7 @@ import * as _ from './style'; import axios from 'axios'; interface PropsType { - props: AttachmentResponse[]; + props: AttachmentResponse[] | null | undefined; } export function AttachedBox({ props }: PropsType) { @@ -43,7 +43,7 @@ export function AttachedBox({ props }: PropsType) { <_.AttachedWrapper> <_.AttachmentTitle>첨부자료 <_.Attachments> - {props.map((attachment, index) => ( + {props?.map((attachment, index) => ( <_.Attachment key={index}>