When I remove the if-stament I get the data and doc.data() works, but I need to check for type ‘added’ so I don’t output existing data again and again.
With the if-statement, I get this error message:
Uncaught TypeError: doc.data is not a function
async getChats(callback){
const roomFilter = query(colRef, where("room", "==", this.room));
const ordered = query(roomFilter, orderBy('created_at'));
this.unsub = onSnapshot(ordered, (snapshot) => {
let items = []
snapshot.docChanges().forEach(doc => {
if(doc.type === 'added'){
items.push({ ...doc.data(), id: doc.id })
console.log(items);
callback(items);
}})
});