I am working on a Firebase project in React JS and I need to append the data from the database to an array. When I add to the array like this:
const db = firebase.firestore()
const docData = []
useEffect(() => {
db.collection("articles").get().then((querySnapshot) => {
querySnapshot.forEach((doc) => {
docData.push(doc.data())
});
});
console.log(docData)
}, [])
This properly displays the data in the console, however when I return the data outside of the useEffect like this:
return (
<div className="App">
{docData}
</div>
);
This does not return any array. I am new to React JS and any help would be appreciated.