Hello, I’m currently trying to display information from an API, but it doesn’t seem to be working. Right now I have it wait for the information to be fetched, and then I try to display it, but when I get to the displaying part, nothing happens.
May I have some help?
This is what my code look like as of now:
import React from 'react';
import { StyleSheet, Text, View, ActivityIndicator } from 'react-native';
export default class App extends React.Component {
constructor(props) {
super(props);
this.state = {
isloading: true,
dataSource: null,
}
}
componentDidMount() {
return fetch('https://api.vexdb.io/v1/get_teams')
.then((response) => response.json())
.then((responseJson) => {
this.setState({
isloading: false,
dataSource: responseJson.result,
})
})
.catch((error) => {
console.log(error)
});
}
render() {
if (this.state.isloading) {
return(
<View style={styles.container}>
<ActivityIndicator/>
</View>
)
} else {
let teams = this.state.dataSource.map((val, key) => {
return <View key={key} style={styles.item}>
<Text>{val.result}</Text>
</View>
});
return (
<View style={styles.container}>
{teams}
</View>
);
}
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: '#fff',
alignItems: 'center',
justifyContent: 'center',
},
item: {
flex: 1,
color: '#FF0000',
}
});
Thank you in-advance.