Здравствуйте , ребят . Помогите по реакт нативу , у кого есть время .. Я новенький. пытаюсь спарсить данные с api прогноза погоды на экран. В коносль вывожу все данные без проблем, но как пытаюсь вывести на экран , выдает постоянно - undefined is not an object (evaluating '
this.state.todos.weather[0]') .
и да, делаю все на сайте
snack.expo.io . То , что закомментил с console.log , работает. а ниже , вывод на экран - нет.
вот код
import React, { Component, createElement } from 'react';
import {
StyleSheet,
Text,
View,
Image,
ImageBackground,
ActivityIndicator
} from 'react-native';
class App extends Component {
constructor(props) {
super(props);
this.state = {
todos: {},
isLoading: true,
};
}
componentDidMount = async () => {
fetch(
'
https://api.openweathermap.org/data/2.5/weather?q=tbilisi,ge&units=metric&apikey=76dc3c2357c096b0f5e4ae5490f7f2be'
)
.then(res => res.json())
.then(data => {
this.setState({ todos: data });
// const data = this.settState({todos: data})
// console.log(data.coord.lon)
// console.log(
data.coord.lat);
// console.log(
data.weather[0].main);
// console.log(
data.weather[0].description);
})
.catch(error => console.error(error))
.finally(() => {
this.setState({ isLoading: false });
});
};
render() {
// const { data, isLoading } = this.state;
return (
<View>
<Text>
{
this.state.todos.weather[0].description}
</Text>
</View>
);
}
}