0

can anyone tell me? I get an array of messages, through api, it contains id, body, owner name "messages": [ { "id": "1", "createdAt": "2019-10-23T12:58:22.933Z", "body": "Hello", }, .....

How can I write it as an array for giftedchat, what would it be "messages": [ { "_id": "1", "createdAt": "2019-10-23T12:58:22.933Z", "text": "Hello", }, .....

And there are 10 messages, that is, how to iterate over to write values ​​from one array to another

Just for a flatlist, there goes render and selects, name: item.ownername, is there something similar that could be used for messages in gifted chat?

Maycon Mesquita
  • 4,470
  • 2
  • 21
  • 29
ike13
  • 137
  • 1
  • 11
  • you can simply map messages array from your apicall to the desired form of array for Gifted chat.Can you elaborate more for your needs? – Dipesh KC Apr 26 '20 at 17:32

1 Answers1

0

You should map your array to get the same format as needed for GiftedChat

const newArray = messages.map(message => ({ _id: message.id, createdAt: message.createdAt, text: message.body, user: { _id: //user_id, name: //username } }))
Mahdi N
  • 2,128
  • 3
  • 17
  • 38