11import { useNavigate } from 'react-router-dom' ;
2- import { useState } from 'react' ;
2+ import { useState , useEffect } from 'react' ;
33import profile from '../assets/profile.svg' ;
44import logoWidth from '../assets/logoWidth.png' ;
5+ import { getProfileDownloadUrl } from '../api/mypage' ;
6+
57
68export default function Header ( ) {
9+ const [ profileImage , setProfileImage ] = useState ( null ) ;
10+
11+ const fetchProfileImage = async ( ) => {
12+ try {
13+ const response = await getProfileDownloadUrl ( ) ;
14+ return response . downloadUrl ;
15+ } catch ( error ) {
16+ console . error ( '프로필 이미지 로드 실패:' , error ) ;
17+ return null ;
18+ }
19+ } ;
20+ useEffect ( ( ) => {
21+ const loadProfileImage = async ( ) => {
22+ const imageUrl = await fetchProfileImage ( ) ;
23+ setProfileImage ( imageUrl ) ;
24+ } ;
25+ loadProfileImage ( ) ;
26+ } , [ ] ) ;
27+
728 const navigate = useNavigate ( ) ;
829 return (
930 < div className = "sticky top-0 z-50 backdrop-blur-md bg-blue-400/80 w-screen h-16 flex items-center justify-between px-4 shadow-md" >
@@ -12,9 +33,15 @@ export default function Header() {
1233 onClick = { ( ) => navigate ( '/home' ) }
1334 />
1435
15- < img src = { profile } alt = "profile" className = "w-8 h-8 cursor-pointer"
16- onClick = { ( ) => navigate ( '/mypage' ) }
17- />
36+ { profileImage ? (
37+ < img src = { profileImage } alt = "profile" className = "w-8 h-8 cursor-pointer rounded-full object-cover"
38+ onClick = { ( ) => navigate ( '/mypage' ) }
39+ />
40+ ) : (
41+ < img src = { profile } alt = "profile" className = "w-8 h-8 cursor-pointer"
42+ onClick = { ( ) => navigate ( '/mypage' ) }
43+ />
44+ ) }
1845 </ div >
1946 ) ;
2047}
0 commit comments