How to use multiples "onSnapshot" changes using Reactjs?
Does someone has used multiples "onSnapshot" in a ReactJs app?
In this video React Firebase CRUD Tutorial Maksim Ivanov show that we can subscribe to firestore Changes by returning teh "onSnapshot" output, like this:
React.useEffect(() => {
return db.collection("dashboars").onSnapshot((snapshot) => {
snapshot.forEach(doc => {
dashboardsData.push({ ...doc.data(), id: doc.id });
});
setDashboards(dashboardsData);
});
}, []);
In my case, each "dashboards" has "cards" collection with "devicesId". In another collecton there is the relative devicesId with name and status.
I need to show any change in the dashboard, card, and devices on the screen.
Collection "dashboards" /dashboards/OKtApgxGYeMDst/cards/KgKXJrg9SDvXVC returns {devicedId:"esp32_456194"}
Dashboard name: "DASHBOARD 01"
..Card name: "esp32_AF49AC (dev)"
..Card name: "esp32_455FE8"
..Card name: "esp32_45A134"
..Card name: "esp32_456194"
....DeviceId: "esp32_456194"
Collection "devices"
DevideId: "esp32_456194"
--> name: "ED 01", status: "on"
--> name: "ED 02", status: "off"
--> name: "SD 01", status: "off"
--> name: "SD 02", status: "off"
