Ive searched for problems like this but haven't found solution yet. When I console.log(data)
I see the object with all the proper data. When i try to access it with data.name
(or any other property on the object) nothing happens, even intellisense doesn't have anything for it.
const key = process.env.REACT_APP_WEATHER_API_KEY;
const [data, setData] = React.useState<{}>({});
const url = `https://api.openweathermap.org/data/2.5/weather?q=Lethbridge&units=imperial&appid=${key}`;
const getWeatherData = async () => {
if (longitude && latitude !== undefined) {
axios
.get(url)
.then(response => {
const returnedData = response.data;
setData(returnedData);
})
.catch(err => console.log('Error:', err));
}
};
React.useEffect(() => {
getWeatherData();
console.log('data', data);
}, []);
When i console.log('data')
though i see the object returned from api request proper like this.