1const [rooms, setRooms] = useState([]);
2
3useEffect(() => {
4 const getRooms = db.collection('rooms').onSnapshot((snapshot) => {
5 setRooms(
6 snapshot.docs.map((doc) => {
7 return { id: doc.id, data: doc.data() };
8 })
9 );
10 });
11 return () => {
12 getRooms();
13 };
14}, []);