Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR TYPESCRIPT

apply limit to fetch number of documents firebase firestore

// imports
import React, { useEffect, useState } from "react";
import { db } from "../firebase";
import {
    onSnapshot,
    collection,
    query,
    where,
    limit,
} from "firebase/firestore";

// code 

const [data, setData] = useState([]);
    useEffect(() =>
        onSnapshot(
            query(
                collection(db, "products"),
                where("trending", "==", true),
                limit(8)
            ),
            (snapshot) => {
                setData(
                    snapshot.docs.map((doc) => {
                        return { ...doc.data() };
                    })
                );
            }
        )
    );
 
PREVIOUS NEXT
Tagged: #apply #limit #fetch #number #documents #firebase #firestore
ADD COMMENT
Topic
Name
9+3 =