diff --git a/src/pages/Profile.jsx b/src/pages/Profile.jsx index 298bf19..41ff769 100644 --- a/src/pages/Profile.jsx +++ b/src/pages/Profile.jsx @@ -12,7 +12,7 @@ const Profile = ({ userInfo }) => { const refreshTimerRef = useRef(null); const maxExp = userInfo.petGrow === "EGG" ? 150 : userInfo.petGrow === "HATCH" ? 300 : 300; - + // 티어 아이콘 매핑 const tierEmojis = { SEED: "🫘", @@ -38,13 +38,13 @@ const Profile = ({ userInfo }) => { setIsRefreshing(true); try { // 실제로는 여기서 API 호출을 통해 최신 데이터를 가져옵니다 - const response = await fetch("/api/user/info", { + const response = await fetch("/api/user/info", { credentials: 'include', headers: { 'Cache-Control': 'no-cache' } }); - + if (response.ok) { const data = await response.json(); // 새로운 데이터로 상태 업데이트 @@ -63,7 +63,7 @@ const Profile = ({ userInfo }) => { // 자동 새로고침 설정 (30초마다) useEffect(() => { refreshTimerRef.current = setInterval(refreshProfileData, 30000); - + // 컴포넌트 언마운트 시 타이머 정리 return () => { if (refreshTimerRef.current) { @@ -73,23 +73,22 @@ const Profile = ({ userInfo }) => { }, []); // userInfo가 변경되면 값 업데이트 - useEffect(() => { - setSeasonCommitCount(userInfo.seasonCommitCount || 0); - setPetExp(userInfo.petExp || 0); - setLastRefreshTime(new Date()); - }, [userInfo]); +useEffect(() => { + setSeasonCommitCount((prev) => prev || userInfo.seasonCommitCount); + setPetExp((prev) => prev || userInfo.petExp); +}, [userInfo]); // 날짜 포맷팅 함수 const formatDate = (dateString) => { if (!dateString) return "없음"; const date = new Date(dateString); - return date.toLocaleDateString('ko-KR', { - year: 'numeric', - month: 'long', - day: 'numeric' + return date.toLocaleDateString('ko-KR', { + year: 'numeric', + month: 'long', + day: 'numeric' }); }; - + // 새로고침 시간 포맷팅 함수 const formatRefreshTime = (date) => { return date.toLocaleTimeString('ko-KR', { @@ -152,10 +151,10 @@ const Profile = ({ userInfo }) => { {/* 왼쪽: 펫 이미지 */}