Can I use mysql to save the message?
tranvannhat opened this issue ยท 6 comments
tranvannhat commented
Issue Description
Can I use mysql to save the message?
Can I customize the message object? Compulsory use of your format?
xpsdeset commented
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.
xcarpentier commented
Hi, I add this question to readme/questions ;)
Simwenya commented
how do you connect giftedChat to mysql
tranvannhat commented
thanks bro. Closed
LesedimotaungNC commented
a graphql example would be awesome
josemiguelo commented
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)}
.....
/>
)