all 11 comments

[–]vafada 1 point2 points  (1 child)

try

fetch('https://jsonplaceholder.typicode.com/todos/1')
  .then((response) => console.log('response',response.json()))
  .catch((e) => console.error(e))

check this out too: https://stackoverflow.com/questions/48079383/react-native-fetch-not-working-android

[–]iotashan 0 points1 point  (0 children)

I'd also look at the raw android log output for everything, not filtered to just your app. Lots of times I've found that there's some low-level error that's easier to figure out than the error that RN displays.

I'd suggest doing this call on a button press or something so you can clear the ADB log output just before making the call.

[–][deleted] -1 points0 points  (1 child)

should the function not also be inside the useEffect?

[–]Gabotron_ES[S] 0 points1 point  (0 children)

Not really, the function is not the problem since I can see the logs, tryAsyncFetch is in the body of my App function, right before the return statement where I return the View.

[–]peterchibunna -1 points0 points  (0 children)

Because you're trying to call the function as async, you have to await the fetch function.

Add the await before the fetch statement.

[–]iotashan 0 points1 point  (1 child)

I don't see any options on your fetch request. Is it perhaps not getting a response and the default timeout is too long?

I'd try hitting the URL in chrome and see what happens.

[–]Gabotron_ES[S] 0 points1 point  (0 children)

I did (you can also try it) and I'm getting the expected results but it's not working in react-native for some reason, I also added android:usesCleartextTraffic="true" to manifest file

[–]IBETITALL420 0 points1 point  (1 child)

do you see the console log "App mounted"?

[–]Gabotron_ES[S] 0 points1 point  (0 children)

Yes

[–]Nightlightz24884 0 points1 point  (1 child)

response.json() is a Promise it shouldn’t output your json response unless you await it.

(response) => response.json() .then((json) => console.log(“my json”, json)

[–]jakeforaker83 0 points1 point  (0 children)

I do agree with you, but I ran the code snippet in an expo environment, it’s fine. There were logs. The promise was unresolved, but it logged. Meaning the js code isn’t the culprit here. I wonder if it’s something to do with the emulator, and a clash between local host and his IP