0

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
Haren Sarma
  • 1,848
  • 3
  • 34
  • 56
  • `setState` was explained in this related [post](https://stackoverflow.com/a/57451615/16531380) that you can check to understand more about it. – RJC Jan 31 '22 at 07:45

0 Answers0