I am not getting any way to setState inside firestore onsnapshot method. please help me to find my mistake:
firestore()
.collection('Chats')
.where('trip_id', '==', this.props.route.params.tripId)
.onSnapshot(snapshot => {
var chats = [];
snapshot.forEach(async e => {
chats.push({
sent_by: e.data().sender_id,
message: e.data().message,
});
});
console.log(chats); /// working here
this.setState({
chatmessage: chats, /// not working
chatwindow: true,
});
});
console.log(this.state.chatmessage); /// not working