I don't know if it is a bug or something wrong with my code. But the first fetch takes to long to respond. Although this problem is only on the app. When I run it on the web, it works like a charm and load within 2 to 3 seconds. While on the app it takes more than a minute.
fetch(url)
.then((response)=>response.json() )
.then((responseJson)=>{
setDATA(responseJson);
setLoading(false);
})
.catch((err)=>{
console.log(err)
})
I also used Axios but having the same problem
axios.get(url)
.then(res => {
setDATA(res.data);
setLoading(false)
console.log(DATA);
})
If you think this can be a large data problem. the SQL db has only 2 field to fetch from. And It is same when i try to login user. Same slow fetch and slow response
fetch(url, {
method: 'POST',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json',
},
body: JSON.stringify({
email: email,
password: password
}),
})
.then(response => response.json())
.then((responseJson) => {
setLoading(false);
// If server response message same as Data Matched
if (responseJson === 'Data Matched') {
// save user to async
// AsyncStorage.setItem('isLoggedIn', true);
//send user to main page
navigation.navigate('flatlist');
} else {
alert(responseJson);
console.log(responseJson)
}
})
.catch((error) => {
setLoading(false);
console.log(error);
});
};
It also seems like a bug as I read this