0

When I close the app the text is cleared, using firebase to pull data how can I append them into gifted-chat?

  onSend(messages = []) {
    _userText.push({message: messages});

    this.setState(previousState => ({
      messages: GiftedChat.append(previousState.messages, messages),
    }))
  }

This will trigger when i input send from keyboard.

InsXghT
  • 53
  • 2
  • 10

1 Answers1

1

Using this below approach can help you rendering data into you gifted chat

this.setState(previousState => ({
          messages: GiftedChat.append(previousState.messages, {
            _id: "MSG ID",
            text: "TEXT YOU WANT TO SHOW",
            createdAt: new Date(),
            user: {
              _id: "USER_ID",
              name: "USER NAME",
              avatar:"USER AVATAR URL",
            },
          }),
        }));

Hope this will help you through your problem ,

HpDev
  • 2,789
  • 1
  • 15
  • 20
  • Well if you send the message from the `GiftedChat` component using the `onSend` prop, you don't need to structure the object manually. The component will format the message exactly how you need when it appends to your `messages` state. – Dylan Powers May 10 '20 at 03:24
  • This above method is used to append the previous msg, which was store in firebase data base , so once you call the firebase function and set the msg in internal state in react component , after that you can use this method to append previous msg on the mobile screen – HpDev May 11 '20 at 01:15