React-native-gifted-chat: Can I use mysql to save the message?

Created on 1 Feb 2018  路  6Comments  路  Source: FaridSafi/react-native-gifted-chat

Issue Description

Can I use mysql to save the message?
Can I customize the message object? Compulsory use of your format?

Most helpful comment

Hi, I add this question to readme/questions ;)

All 6 comments

Yes you can use mysql to save messages.
Use the text generated by send button to insert into your mysql.
Also you can use any format just map it when populating the chats.

Hi, I add this question to readme/questions ;)

how do you connect giftedChat to mysql

thanks bro. Closed

a graphql example would be awesome

a graphql example would be awesome

This has worked for me (you have to use withApollo HOC and use prop 'client'):

....
const onSend = (newMessages: IMessage[] = []) => {
    newMessages.forEach(message => {
      client
        .mutate({
          variables: {
            ...
          },
          mutation: YOUR_MUTATION,
        })

        .then(response => {
          setMessagesHistory(prevMessages =>
            GiftedChat.append(prevMessages, message)
          )
        })
        .catch(error => {
          // error logic
        })
    })
  }
....
 return (

        <GiftedChat
          messages={yourMessagesFromState}
          onSend={messages => onSend(messages)}
          .....
        />
 )
Was this page helpful?
0 / 5 - 0 ratings