Comment on page
useMessages hook
add to imports section
import { useMessages } from '@minchat/react';
Messages retrieved in a conversation are paginated to 25 messages at a time.
const { messages, loading , error, sendMessage , paginate , paginateLoading } = useMessages(chat)
Field | Type | Description |
---|---|---|
messages | the list of messages returned. this is automatically updated whenever a new message is received for the current conversation | |
loading | boolean | Shows the state of querying the messages, used to update your UI to show loading state |
error | object | an error object that is defined if an error occured while trying to query the messages. |
sendMessage | function | function called to send a message to the conversation |
paginate | function | function called to get the next 25 messages, the messages are automatically added to the begining of the messages array. |
paginateLoading | boolean | Shows the state of a paginated query for messages, used to update your UI to show pagination state. is true when the paginate function is called and is false when messages are returned |
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
ParametersField | Type | State | Description |
---|---|---|---|
text | string | optional | the text of the message |
file | File | optional | upload a file as an attachment |
metadata | json object | optional | an optional key value pair for any additional message information such as custom font size, font type, or JSON formatted string. accepts string,number and boolean values |
Callback
Field | Type | Description |
---|---|---|
data | the message that was sent |
Last modified 2mo ago