Я хочу перечислить данные из API, который я использую. Но я получаю ошибку.
// Here I'm getting the data.
componentWillMount() {
tokenner()
.then(responseJson => {
const token = "Bearer " + responseJson.result.token;
this.setState({ token });
fetch(
"myapiurl//notimportant",
{
method: "GET",
headers: {
Accept: "application/json",
"Content-Type": "application/json",
Authorization: token
}
}
)
.then(response => response.json())
.then(responseData => {
this.setState({
isLoading: false,
dataSource: responseData.result
});
});
})
.catch(error => console.warn(error));
}
Затем я использую следующие коды для получения этих данных:
render() {
if (this.state.isLoading) {
return (
<View style={styles.container}>
<ActivityIndicator />
</View>
);
} else {
console.warn(this.state.dataSource) // I got the data. Everything ok.
this.state.dataSource.map((val, key) => {
return ( // There was no data returned error.
<View key={key} style={styles.item}>
<Text>{val.id}</Text>
<Text>{val.name}</Text>
<Text>{val.surname}</Text>
<Text>{"Sıra" + key}</Text>
</View>
);
});
}
}
}
ошибка:
Ошибка
Программа не выдает ошибку, когда я печатаю результат без использования цикла.
Что мне делать?