I am using for await loop to iterate through an array and match a value inside firestore cloud but unfortunately the result is not coming as expected; here is my code
(async () => {
for await (const element of array) {
firestore().collection('users').where('value', '==', element).get()
.then(async snapshot () => {
setvalue(snapshot.data())
}
setIsLoading(false);
}();
When i run the app in emulator and array contains 2 items, it just give me the result as expected, but when the array is above then 40 or nth number, then the result is not updating as exptected, and after a few minutes, the expected result is display. I just want to update the isLoading state false, when the for await loop finishes its loop and also the code inside the loop block finished checking the firebase then only the setIsLoading(false)
You can consider using Promise.all, and wait for all operations to finish.
As per previously advised, better to break it down to chunks and use where('value','in', array) instead.
Update - use For loop (I break them down into steps so you can modify for your own use)