I've encountered a challenge while trying to extract data from a weather API. I am able to access the information that is not stored in an array as it is just an object. However, I'm facing difficulties with retrieving data from the WEATHER array. Please refer to the image for more details. Surprisingly, no error messages are being displayed in the console!
Here's what's working:
.then((json) => setData(json.coord))
<Text style={styles.h1}>{data.lon}</Text>
However, I'm struggling to access the weather data. Any help or guidance on this issue would be highly appreciated!
Currently, my objective is to fetch data from the API and specifically retrieve json.weather.
const Weather = () => {
const [isLoading, setLoading] = useState(true);
const [data, setData] = useState([]);
useEffect(() => {
fetch('https://api.openweathermap.org/data/2.5/weather?q=Rotterdam&appid=f7c5a6722f37c1cb782a66e9b904178')
.then((response) => response.json())
.then((json) => setData(json.weather))
.catch((error) => console.error(error))
.finally(() => setLoading(false));
});
return (
<View>
<NotiScreen/>
<Text style={styles.h1}>{weather.id}</Text>
</View>
);
}