Reputation: 530
when I try to run the code below in chrome console it works and I get alert in the browser but when I try to run the same code inside react native environment, I get an error instead: "TypeError: Network Request Failed".
makeRequest(){
fetch('http://localhost:3000/')
.then(response => response.json())
.then(data => alert(data))
.catch(e => alert(e));
}
render() {
return(
<View style = {styles.main}>
{setTimeout(()=>this.makeRequest(),1000);}
</View>
)
}
Upvotes: 4
Views: 3592
Reputation: 31
return fetch('http://<your ip>')
.then((response) => response.json())
.then((responseJson) => {
console.log(responseJson);
})
.catch((error) => {
console.error(error);
});
Upvotes: 0