I'm working with react in combination with firebase. I'm trying to export all firebase stuff to separate files but strugeling with the return of an array. Which is kind of .. well.
I have App.js which looks similar to this:
import { getDataFromFirebase } from './somewhere'
export default function App() {
useEffect(() => {
setA(getDataFromFirebase())
}, [])
const [a, setA] = useState([])
Then I have the firebase file with one get function which looks like this:
export function getDataFromFirebase() {
let aArr = []
db
.collection('user')
.get()
.then(function(querySnapshot) {
querySnapshot.forEach(function(doc) {
let aObj = doc.data()
aObj._id = doc.id
aArr = [...aArr, aObj]
})
})
}
This way I'm ending up with aArr which includes all users + their id. Now I've tried to pass the array to app so I can use it there but it won't work. All I get is undefined when I try to return aArr in line 10. I'm clearly missing something. Can anyone help?