import { useQuery } from 'react-query'; type WeatherType = { weather: Array<{ id: number main: string description: string icon: string }> } // 날씨 정보를 얻기 위한 함수 const fetchWeather = async () => { const res = await fetch(`https://api.openweathermap.org/data/2.5/weather?q=Seoul&lang=kr&appid=ef23a61e94f59784b8451d12c0d07da8`); if (res.ok) { return await res.json() as WeatherType; } throw new Error(res.statusText); }; export default function QuerBasic() { // fetchWeather 함수로 데이터 가져오기 const { data, isLoading, isError, error } = useQuery('weather', fetchWeather); if (isLoading) { return

Loading...

} if (isError) { return

Error: {error.message}

} return (
{data?.weather?.[0]?.main}
{data?.weather?.[0]?.description}
); }