I used firebase with React to create and call my API which contains more than 50 types of flowers with descriptions . Therefore, I want to display only 7 flowers randomly in the home page as the page loads. I also have a flower's page which displays all the flowers. Right now, this code just displays all the data as the page loads.
const getPlants = async () => {
const data = await getDocs(plantsCollectionRef);
setPlants(data.docs.map(doc => ({ ...doc.data(), id: doc.id })));
};
getPlants();
}, []);
And this is what I'm returning...
return (
<div className="plant-card" key={plant.id}>
<img src={plant.image} alt={plant.name} loading="lazy" />
<div>
<h3>{plant.name}</h3>
<p>${plant.price}</p>
</div>
<div>
<p>Read more...</p>
<p>Buy</p>
</div>
</div>
);
})}
Pls, help me out.