useMessages hook

the useMessages hook is used to interface with messages belonging to a Chat.

add to imports section
import { useMessages } from '@minchat/react';

Get Messages

Messages retrieved in a conversation are paginated to 25 messages at a time.

const {
         messages,
         loading,
         error,
         paginate,
         paginateLoading,
         sendMessage,
         updateMessage,
         deleteMessage

      } = useMessages(chat)

Send Message

To send a message, call the sendMessage(...) function from useMessages hook.

const message = {
    text: "Hello World!"
}

const callback = (data)=> { /**      */}

sendMessage(message, callback) 

New messages received are automatically added to the messages variable of useMessages(...)

Message Parameters

Callback

Update Message

To update a message, call the updateMessage(...) function from useMessages hook.

const message = {
    text: "Updated Hello World!"
}

const callback = (data)=> { /**    
    do something
 */}

updateMessage(messageId, message, callback) 

messages are automatically updated in the messages variable of useMessages(...)

Parameters

Message Parameters

Callback

Delete Message

To delete a message, call the deleteMessage(...) function from useMessages hook.

deleteMessage(messageId)  

Parameters

Last updated