'React: Lazy Load Firestore documents

I want to lazy load data from my Firestore Collection, and I dont seem to find anything like this in the documentation and on google. This is my current code:

async function fetchProducts() {
    const q = query(collection(db, "posts"), orderBy("uploadTime", "desc"));
    const querySnapshot = await getDocs(q);
    querySnapshot.forEach((doc) => {
        setProductsState(oldArray => [...oldArray, doc.data()])
    });
}

I want it to load for example 10 posts, and when the user reaches the bottom of the page, it loads 10 more and so on! Thank you for your help.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source