11'use client' ;
22
3- import { useEffect , useState } from 'react' ;
4- import { GoogleMap , LoadScript , Marker } from '@react-google-maps/api' ;
3+ import { useState } from 'react' ;
4+ import { GoogleMap , Marker , useJsApiLoader } from '@react-google-maps/api' ;
55import Image from 'next/image' ;
66
77export default function HomecomingPage ( ) {
@@ -219,44 +219,35 @@ function Invitation({onBack}) {
219219}
220220
221221function HomecomingMap ( ) {
222- const [ isGoogleReady , setIsGoogleReady ] = useState ( false ) ;
223-
224- useEffect ( ( ) => {
225- if ( typeof window === 'undefined' ) return ;
226-
227- // 이미 전역에 google.maps가 로드되어 있는 경우
228- if ( window . google && window . google . maps ) {
229- setIsGoogleReady ( true ) ;
230- }
231- } , [ ] ) ;
222+ const { isLoaded, loadError} = useJsApiLoader ( {
223+ googleMapsApiKey : process . env . NEXT_PUBLIC_GOOGLE_MAPS_API_KEY , id : 'homecoming-map-script' ,
224+ } ) ;
232225
233226 const center = { lat : 37.388493 , lng : 126.639989 } ;
234227
235- const handleScriptLoad = ( ) => {
236- setIsGoogleReady ( true ) ;
237- } ;
228+ if ( loadError ) {
229+ return ( < div
230+ className = "rounded-2xl border border-red-300 bg-red-50 text-red-700 text-xs md:text-sm flex items-center justify-center h-[220px] md:h-[320px] lg:h-[420px]" >
231+ 지도를 불러오는 중 오류가 발생했습니다.
232+ </ div > ) ;
233+ }
234+
235+ if ( ! isLoaded ) {
236+ return ( < div
237+ className = "rounded-2xl border border-neutral-200 bg-neutral-100 text-neutral-500 text-xs md:text-sm flex items-center justify-center h-[220px] md:h-[320px] lg:h-[420px]" >
238+ 지도를 불러오는 중입니다...
239+ </ div > ) ;
240+ }
238241
239242 return ( < div
240243 className = "rounded-2xl overflow-hidden border border-neutral-200 bg-neutral-100 h-[220px] md:h-[320px] lg:h-[420px]" >
241- { isGoogleReady ? ( < GoogleMap
242- mapContainerClassName = "w-full h-full"
243- center = { center }
244- zoom = { 17 }
245- options = { { disableDefaultUI : true , clickableIcons : false } }
246- >
247- < Marker position = { center } />
248- </ GoogleMap > ) : ( < LoadScript
249- googleMapsApiKey = { process . env . NEXT_PUBLIC_GOOGLE_MAPS_API_KEY }
250- onLoad = { handleScriptLoad }
251- >
252- < GoogleMap
253- mapContainerClassName = "w-full h-full"
254- center = { center }
255- zoom = { 17 }
256- options = { { disableDefaultUI : true , clickableIcons : false } }
257- >
258- < Marker position = { center } />
259- </ GoogleMap >
260- </ LoadScript > ) }
244+ < GoogleMap
245+ mapContainerClassName = "w-full h-full"
246+ center = { center }
247+ zoom = { 17 }
248+ options = { { disableDefaultUI : true , clickableIcons : false } }
249+ >
250+ < Marker position = { center } />
251+ </ GoogleMap >
261252 </ div > ) ;
262253}
0 commit comments