I am trying to fetch data from external api and show that on display. When I press button it calls function which console things normally but can't show returned value.
export default function HomeScreen() {
return (
<View style={styles.container}>
<Button title='show data' onPress={loadText}/>
<Text>{loadText}</Text>
</View>
);
function loadText(){
fetch('http://192.168.88.253:5000/read')
.then((response) => response.json())
.then((responseJson) => {
return (
console.log(responseJson.city)
);
})
.catch((error) => {
console.error(error);
});
}
}
If I understand it, loadText
function must return responseJson.city
value as a string.
How can I show it in <View>
or <Text>
?