I am trying to pull a collection of users from FireStore in react with an async function. The code is only pulling one user when I want all users from the collection.
I am new to react and firestore and not sure what I am doing wrong. I have looked through firestore documentation, yet I have been unable to resolve issue.
Thank you for any help!
function Pull() {
const [blogs,setBlogs]=useState([])
const fetchBlogs=async()=>{
const response=firestore.collection('user');
const data= await response.get();
data.docs.forEach(item=>{
setBlogs([blogs,item.data()])
console.log(data)
})
}
useEffect(() => {
fetchBlogs();
}, [])
return (
<div className="App">
{
blogs.map((items)=>
<div className="blog-container">
<h4>{items.user}</h4>
</div>
)
}
</div>
);
}
export default Pull;