FaridSafi / react-native-gifted-chat

đź’¬ The most complete chat UI for React Native

Home Page:https://gifted.chat

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Can I use mysql to save the message?

tranvannhat opened this issue · comments

Issue Description

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

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 ;)

commented

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)}
          .....
        />
 )