Ответ, который вы получаете от API, является объектом, и вам необходимо использовать плоский список, поскольку вы просто показываете три текста здесь, вы можете сделать что-то вроде этого:
import React from 'react';
import {View , Text, FlatList } from 'react-native';
class Global extends React.Component{
constructor(){
super();
this.state = {
global: {},
refreshing: false
}
}
componentDidMount = () => {
this.getDataApi();
}
getDataApi = async () => {
this.setState({ refreshing: true})
fetch('https://covid19.mathdro.id/api')
.then(response => response.json())
.then(json => {
this.setState({ global: json })
})
}
render(){
return (
<View style={{flex:1,justifyContent:"center",alignItems:"center"}}>
{this.state.global.confirmed != undefined ? <Text> Positif: {this.state.global.confirmed.value} </Text> : null}
{this.state.global.confirmed != undefined ? <Text> Sembuh: {this.state.global.recovered.value} </Text> : null}
{ this.state.global.confirmed != undefined ? <Text> Meninggal: {this.state.global.deaths.value} </Text> : null}
</View>
)
}
}
export default Global;
Надеюсь, это поможет!