get data from firebase database code example
Example: recieve data from firebase database
const [rooms, setRooms] = useState([]);
useEffect(() => {
const getRooms = db.collection('rooms').onSnapshot((snapshot) => {
setRooms(
snapshot.docs.map((doc) => {
return { id: doc.id, data: doc.data() };
})
);
});
return () => {
getRooms();
};
}, []);