I am beginner in react and just want to interrogate a server and display its answer. I have the following code :
My React code is:
export default class AskServer extends Component {
interrogateServer = () => {
fetch('https://www.-----/test.php')
.then((response) => response.json())
.then((responseJson) => {
console.log(responseJson.myText)
return responseJson.myText
})
.catch((error) => {
console.error("pb occured");
});
}
render () {
return (
<View >
<Text> Answer of the server is </Text>
<Text> {this.interrogateServer()} </Text>
</View>
);
}
}
And on the server, in PHP is just
<?php
$z= '{
"myText": "hello"
}';
echo $z;
?>
But what is displayed is just: "Answer of the server is"
Could you explain me why the word "hello" is not displayed on screen (but is visible in console log) ?