So I am calling this function from a useEffect hook in React Native, the issue is within the function as the function contains a for await loop. The console.log outside the function works but all of the code inside the for await doesn’t run. how do I fix this?
Here is the function:
const addBook = async () => {
console.log('IT IS HAPPENING!!!! 2');
for await (const book of selectedBooks) {
console.log('IT IS HAPPENING!!!! 3');
setIdSearchValue(book.id);
console.log('ID SREARCH VALUE', book.id);
console.log(' ~ screenTransfer ~ selectedBooks[i].id:', book.id);
await getBooksQuery.refetch(); // Wait for data to be fetched
console.log('ENABLE BOOKS QUERY VALUE', enableBooksQuery);
console.log('GETBOOOKSQUERYDATA', getBooksQuery.data);
console.log('GETBOOOKSQUERYERROR', getBooksQuery.isError, getBooksQuery.error);
}
};
I tried switching the for await to a regular for loop with the same await but it still doesn’t work. I am Expecting to see all of the console.logs in the for await to be ran.