1 db.collection("users").get().then((querySnapshot) => {
2 querySnapshot.forEach((doc) => {
3 console.log(`${doc.id} => ${doc.data()}`);
4 });
5
1useEffect(() => {
2 db.collection('posts')
3 .orderBy('timestamp', 'asc') // optional
4 .onSnapshot((snapshot) => {
5 setPosts(
6 snapshot.docs.map((doc) => {
7 return doc.data();
8 })
9 );
10 });
11}, []);
1//retrieve one document and save it to userDetails
2const [userDetails, setUserDetails] = useState('')
3db.collection('users').doc(id).get()
4 .then(snapshot => setUserDetails(snapshot.data()))
1const [hospitalsDetails, setHospitalsDetails] = useState([])
2 useEffect(()=>{
3 //load hospitals into hospitalsList
4 const hospitals = []
5 db.collection('Hospitals').get()
6 .then(snapshot => {
7 snapshot.docs.forEach(hospital => {
8 let currentID = hospital.id
9 let appObj = { ...hospital.data(), ['id']: currentID }
10 hospitals.push(appObj)
11
12 hospitals.push(hospital.data())
13 })
14 setHospitalsDetails(hospitals)
15 })
16 },[])
17