import { useState, useEffect, Fragment } from 'react'; import { Weather, ApiResponse } from '../../../interfaces'; import axios from 'axios'; import WeatherIcon from '../../UI/Icons/WeatherIcon/WeatherIcon'; import classes from './WeatherWidget.module.css'; const WeatherWidget = (): JSX.Element => { const [weather, setWeather] = useState({ externalLastUpdate: '', tempC: 0, tempF: 0, isDay: 1, conditionText: '', conditionCode: 1000, id: 0, createdAt: new Date(), updatedAt: new Date() }); const [isLoading, setIsLoading] = useState(true); useEffect(() => { axios.get>('/api/weather') .then(data => { setWeather(data.data.data[0]); setIsLoading(false); }) .catch(err => console.log(err)); }, []); return (
{isLoading ? 'loading' : (
{weather.tempC}°C {weather.conditionCode}
) }
) } export default WeatherWidget;