From 9a4a13c3dc8b0d4c22dafb48b1c40c2b848338c1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EB=AF=BC=EC=88=98?= Date: Mon, 19 Jan 2026 20:23:06 +0900 Subject: [PATCH 1/2] =?UTF-8?q?refactor:=20NoticePage=20=EC=84=B1=EB=8A=A5?= =?UTF-8?q?=20=EC=B5=9C=EC=A0=81=ED=99=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/entry-user/src/pages/NoticePage.tsx | 51 ++++++++++-------------- 1 file changed, 20 insertions(+), 31 deletions(-) diff --git a/apps/entry-user/src/pages/NoticePage.tsx b/apps/entry-user/src/pages/NoticePage.tsx index ce70631..25aeb0a 100644 --- a/apps/entry-user/src/pages/NoticePage.tsx +++ b/apps/entry-user/src/pages/NoticePage.tsx @@ -1,4 +1,4 @@ -import { useEffect, useState } from 'react'; +import { useMemo, useState } from 'react'; import styled from '@emotion/styled'; import { colors, Flex } from '@entry/design-token'; import { NoticePinIcon, TabSection } from '@entry/ui'; @@ -10,7 +10,7 @@ interface NoticeItem { title: string; createdAt: string; isPinned: boolean; - type: 'GUIDE' | 'NOTICE' + type: 'GUIDE' | 'NOTICE'; } const TAB_OPTIONS = [ @@ -18,37 +18,27 @@ const TAB_OPTIONS = [ { key: 'GUIDE', label: '예비 신입생 안내' }, ]; +const formatDate = (dateString: string) => dateString.split('T')[0]; + export const NoticePage = () => { - const [activeTab, setActiveTab] = useState<'NOTICE' | 'GUIDE'>( - 'NOTICE' - ); - const navigate = useNavigate(); + console.count('NoticePage render'); - const handleNoticeClick = (id: number) => { - navigate(`/notice/${id}`); - }; + const [activeTab, setActiveTab] = useState<'NOTICE' | 'GUIDE'>('NOTICE'); + const navigate = useNavigate(); + const { data, isLoading } = useGetAllNotice(activeTab); - const handleTabChange = (tab: string) => { + const handleNoticeClick = (id: number) => navigate(`/notice/${id}`); + const handleTabChange = (tab: string) => setActiveTab(tab as 'NOTICE' | 'GUIDE'); - }; - - const {data, isLoading} = useGetAllNotice(activeTab); - const [noticeItems, setNoticeItems] = useState([]); - - const formatDate = (dateString: string) => { - return dateString.split('T')[0]; - }; - - useEffect(() => { - if (data && Array.isArray(data?.notices)) { - const formattedNotices = data.notices.map(notice => ({ - ...notice, - createdAt: formatDate(notice.createdAt) - })); - setNoticeItems(formattedNotices); - } - }, [data]); + const noticeItems = useMemo(() => { + return ( + data?.notices?.map((notice: NoticeItem) => ({ + ...notice, + createdAt: formatDate(notice.createdAt), + })) ?? [] + ); + }, [data]); return ( @@ -76,12 +66,11 @@ export const NoticePage = () => { {isLoading ? ( 로딩 중... ) : noticeItems.length > 0 ? ( - noticeItems.map((item) => ( + noticeItems.map((item: NoticeItem) => ( handleNoticeClick(item.id)} > - {/* {item.id} */} 공지 {item.isPinned && ( @@ -205,4 +194,4 @@ const NewIconWrapper = styled.span` margin-right: 8px; display: inline-flex; align-items: center; -`; \ No newline at end of file +`; From de5904f9b8c372afe81c5dfd1163925bd30774d8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EB=AF=BC=EC=88=98?= Date: Mon, 19 Jan 2026 20:24:09 +0900 Subject: [PATCH 2/2] fix : noticePage --- apps/entry-user/src/pages/NoticePage.tsx | 2 -- 1 file changed, 2 deletions(-) diff --git a/apps/entry-user/src/pages/NoticePage.tsx b/apps/entry-user/src/pages/NoticePage.tsx index 25aeb0a..210d75d 100644 --- a/apps/entry-user/src/pages/NoticePage.tsx +++ b/apps/entry-user/src/pages/NoticePage.tsx @@ -21,8 +21,6 @@ const TAB_OPTIONS = [ const formatDate = (dateString: string) => dateString.split('T')[0]; export const NoticePage = () => { - console.count('NoticePage render'); - const [activeTab, setActiveTab] = useState<'NOTICE' | 'GUIDE'>('NOTICE'); const navigate = useNavigate(); const { data, isLoading } = useGetAllNotice(activeTab);