Search code examples
javascriptjsonreact-nativefetch

react-native android fetch json stopped working


i am working on a react-native application for about almost a year now, and a function i wrote earlier suddenly stopped working for now reason.. here's the code snippet:

   var array = [];
      fetch('https://reqres.in/api/products/3') //different URL, for testing only
              .then((response) => response.json())
              .then((json) => {  array = json; })
              .then(() => { console.log("get Remote data DONE" + array); 

this code worked great for some time, and now as i had to review my code it suddenly doesn't work anymore.. i get an "network request failed" error msg..

any ideas?


Solution

  • it turns out that the problem was not caused by code i wrote or by any other settings related to react-native. i tried a different emulated device, which i created for testing this issue, and the code completed without any issues at all while debugging on this very device. so i tried to simply wipe my previously used virtual device (https://github.com/google/android-emulator-m1-preview. and now everything is working just fine. problem solved! :)