how to get all the documents in a collection firebase code example
Example: get data from firestore
const [hospitalsDetails, setHospitalsDetails] = useState([])
useEffect(()=>{
//load hospitals into hospitalsList
const hospitals = []
db.collection('Hospitals').get()
.then(snapshot => {
snapshot.docs.forEach(hospital => {
let currentID = hospital.id
let appObj = { ...hospital.data(), ['id']: currentID }
hospitals.push(appObj)
hospitals.push(hospital.data())
})
setHospitalsDetails(hospitals)
})
},[])