// 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() };
})
);
}
)
);