Possible Unhandled Promise Rejection (id:0) Error: network error in react native

Mayank Sharma picture Mayank Sharma · Jul 30, 2018 · Viewed 15.2k times · Source

Possible Unhandled Promise Rejection (id:0) Error: network error in react native

   import React, {Component} from 'react';
   import {View,Text} from 'react-native';
   import axios from 'axios';

   class AlbumList extends Component {
    state = {albums: []};  
   componentWillMount() {
    axios.get('https://rallycoding.herokuapp.com/api/music_albums')
    .then(response=>this.setState({albums: response.data}));
}
renderAlbums() {
return this.state.albums.map(album => <Text>{album.title}</Text>);
}    

render() {
    console.log(this.state);
return(
<View>
  {this.renderAlbums()}
</View>
);
}
};

export default AlbumList;

// I can't load my data from the given link, also in debugging mode there's only //one state created which has empty values and no other data can be visible in //console so help me in fetching the data

Here is screenshot of error I'm getting

enter image description here

Answer

iuliu.net picture iuliu.net · Jul 30, 2018

I think you should try reload app/reinstall app/restart emulator/try on new emulator. I also have had multiple generic network errors using just regular fetch, and they were all related to just the emulator being weird.