I am getting that error when trying to subscribe to realtime updates on firestore via onSnapshot(), using it inside the async function of createAsyncThunk with redux react tools.
The function doesnt wait for the forEach to finish. I have tried a for of loop, but does not work with onSnapshot.
This is my createAsyncFunction.
export const getAuctions = createAsyncThunk(
'auctions/getAuctions',
async () => {
const auctionRef = collection(db, "auctions");
const fetched = [];
onSnapshot(auctionRef, (querySnapshot) => {
for (const doc of querySnapshot.docs) {
fetched.push(doc.data());
};
})
return fetched
}
)
This is called from a dispatch() inside a useEffect one time when the app loads. Any idea?!
Thank you