I am working on my react-app and I am now using react-redux-firebase. Following the step. I want to make it synchronize and use setState() method.
It shows the error:
TypeError: Cannot read property 'then' of undefined
dbGetDate.js
const dbGetData = (store, col, doc, col2, doc2) => {
store.firestore.collection(col).doc(doc).collection(col2).doc(doc2).get().then(data => {
if (data.exists) {
return new Promise((resolve, reject) => {
if(data.data() != null){
resolve(data.data());
}
else{
reject("Some error in fetching data");
}
})
}
else {
return new Promise((resolve, reject) => {
reject("not such data in record");
})
}
}
).catch(function (error) {
return ("Ops, there should be an error");
});
}
export default dbGetData;
myPage.js
componentWillMount(){
const dbStore = dbConnect;
dbGetData(dbStore, 'Test', '123', 'Member','001')
.then(data => {
console.log(data);
this.setState({
firebaseData : data
})
});
}