For 3 different projects, I have been attempting to get fetch or axios to work without success. I've tried adjusting the android manifest as suggested in some troubleshooting threads, but nothing seems to be working. Whether using await/async, promises, or even a simple example like this one, nothing seems to trigger any response - not even the finally statement is executed.
No errors are returned, no logs are generated, simply nothing happens at all.
Upon further investigation, it appears that the Mac/iOS setup works fine, but there seems to be an issue with Windows/Android configurations.
/**
* Sample React Native App
* https://github.com/facebook/react-native
*
* @format
* @flow strict-local
*/
import React, {useEffect} from 'react';
import {SafeAreaView, Text} from 'react-native';
const App = () => {
useEffect(() => {
console.log('hello');
fetch('http://jsonplaceholder.typicode.com/albums')
.then(response => {
console.log('Hello');
console.log(response.json());
})
.then(json => console.log(json))
.catch(error => console.error(error))
.finally(() => console.log('Finally'));
}, []);
return (
<SafeAreaView>
<Text>Hello</Text>
</SafeAreaView>
);
};
export default App;
This is how the package.json file looks:
{
"name": "test",
"version": "0.0.1",
"private": true,
"scripts": {
"android": "react-native run-android",
"ios": "react-native run-ios",
"start": "react-native start",
"test": "jest",
"lint": "eslint ."
},
"dependencies": {
"axios": "^0.21.1",
"react": "17.0.1",
"react-native": "0.64.1"
},
"devDependencies": {
"@babel/core": "^7.12.9",
"@babel/runtime": "^7.12.5",
"@react-native-community/eslint-config": "^2.0.0",
"babel-jest": "^26.6.3",
"eslint": "7.14.0",
"jest": "^26.6.3",
"metro-react-native-babel-preset": "^0.64.0",
"react-test-renderer": "17.0.1"
},
"jest": {
"preset": "react-native"
}
}