Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Android] Fetch takes so much time to call simple api #31539

Closed
pqminh opened this issue May 17, 2021 · 4 comments
Closed

[Android] Fetch takes so much time to call simple api #31539

pqminh opened this issue May 17, 2021 · 4 comments
Labels
Needs: Triage 🔍 Resolution: Locked This issue was locked by the bot.

Comments

@pqminh
Copy link

pqminh commented May 17, 2021

Description

Fetch takes so much time to call simple api. Over 60s

Screen Shot 2021-05-17 at 23 24 25

Screen Shot 2021-05-17 at 23 22 43

React Native version:

react: 17.0.1 => 17.0.1
react-native: 0.64.0 => 0.64.0
Android 10 (debug & release mode)

Steps To Reproduce

let startTime = new Date();
console.log('startTime', startTime.toLocaleString());
fetch('https://reactnative.dev/movies.json')
.then(response => response.json())
.then(json => {
let endTime = new Date();
console.log('endTime', endTime.toLocaleString());
console.log('duration', endTime - startTime);
return json.movies;
})
.catch(error => {
console.error(error);
});

I also try to use axios, xhr but still got this issue. Please help!
repo: https://github.com/pqminh/android-takes-much-time-to-call-api

@sanu23kumar
Copy link

You are not writing fetch as intended in your repo.
Please write your fetch logic in a useEffect(() => {//your code}, [])
In the App function above the return statement and post your results again.

@pqminh
Copy link
Author

pqminh commented May 18, 2021

Only for demo. Pls check App.js file.
TKS!!

@sanu23kumar
Copy link

I did @pqminh, that's why I requested you to move it to the correct place. Right now I've no idea what lifecycle your code is going to follow outside of the app function. It needs to be inside the app function.

@pqminh
Copy link
Author

pqminh commented May 18, 2021

This issue was gone but I didn't change anything.
Maybe due to my network or datetime sync macos & android

Tks for your reply!

@pqminh pqminh closed this as completed May 18, 2021
@facebook facebook locked as resolved and limited conversation to collaborators May 18, 2022
@react-native-bot react-native-bot added the Resolution: Locked This issue was locked by the bot. label May 18, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Needs: Triage 🔍 Resolution: Locked This issue was locked by the bot.
Projects
None yet
Development

No branches or pull requests

3 participants