📌

Untitled

const [weatherInfo, setWeatherInfo] = useState(null);

초기값이 null인 경우에, 맨 처음 UI를 그려줄때 받아오는 data가 없어서 에러가 난다.

useEffect(() => {
	getCurrentLocation();
}, []};

useEffect는 랜더링 후 이루어지는 함수이기 때문에, getCurrentLocation 함수를 실행시켜 data를 받아온다.

따라서 초기에 weatherInfo가 null이었다가 useEffect함수가 바로 실행되면서 data를 받아온다.

{weatherInfo?.name}

{weatherInfo && weatherInfo.name}

→ weatherInfo가 있다면 그 객체의 name을 보여준다.

current location