I am using the fetch api to get data in react native. I don’t know why but I am getting the wrong data back. When I check the api on postman and directly on google it returns the correct data but for some reason, for the same api it returns different or incomplete data in my app.
Sometimes the data is different and sometimes it doesn’t even return the entire data. For example if the data array has 70 objects then it will only return data array with 60 objects.
I am sure this is a silly question but I can’t seem to figure out what the problem is. This is my fetchData
function.
export async function fetchData(url) {
const response = await fetch(url);
const data = await response.json();
return data;
}
This is how I am using the fetchData
function in useEffect
hook.
useEffect(() => {
const getAddData = async (i) => {
const url = "<api url>";
console.log("The url is:", url);
const data = await fetchData(url);
//other code here
}
function configData() {
for(let i = 1; i <= 6; i++) {
const data = await getAddData(i);
}
}
configData();
}, [])
Is my fetchData
function not correct or am I not requesting correctly in the useEffect
hook? or anything else?