0

this code work correctly at Expio.io online but when i tried at Visual studio code Network error come "possible unhandled promise rejection (id 0) react native "

here is code '''

 state={
 Data:[]
 }   
 componentDidMount(){
 axios.get("http://localhost:63007/api/values/GetCoustomer")
.then(response => {
 this.setState({Data: response.data});
 console.log(response.statusText);
 })
.then(error => console.log(error));
 }

'''

  • Hey: have you googled that? I get the following result which seems to match exactly your question: https://stackoverflow.com/questions/38842499/react-native-possible-unhandled-promise-rejection – Pauloco May 06 '20 at 02:14

1 Answers1

1

You're missing a catch block. It should look like this:

axios.get("http://localhost:63007/api/values/GetCoustomer")
  .then(function (response) {
    // handle success
    this.setState({Data: response.data});
 console.log(response.statusText);
  })
  .catch(function (error) {
    // handle error
    console.log(error);
  })
  .then(function () {
    // always executed
  });


cschultz1272
  • 130
  • 8