Skip to main content
This guide covers working with messages inside a conversation: loading the message history, sending new messages, editing and deleting messages, and toggling emoji reactions.

Loading Messages

useLiveChatMessages fetches paginated messages for a conversation. Messages are stored in Redux and kept in sync by the ChatProvider socket.
useChatMessages was renamed to useLiveChatMessages. The old name still works as a deprecated alias.
Messages are sorted oldest-first in the returned array. loadMore fetches messages older than the oldest currently loaded, or retries a load that failed (the failure is in error); refetch reloads the latest page.

Inside a ConversationProvider

ConversationProvider loads its conversation’s messages itself. Read them, with the conversation’s members, from useConversationContext() (or useConversationData({ conversationId }) without the provider):
  • messages, messagesLoading, hasMore
  • messagesError — the last failure loading messages, as a SublayError, or null. Cleared when the next load starts.
  • loadMore() — loads older messages, or retries the load that failed. Never rejects.
  • refetchMessages() — reloads the latest page, replacing the loaded messages (optimistic and newer live ones are kept, and a message on the new page keeps the files / grants another hook fetched for it, except what the server hides on a deleted or removed message: its files (its author still sees the files of their own removed message) and a removed message’s grants). Never rejects.
They share their state with every useLiveChatMessages on the same conversation. A useLiveChatMessages inside the provider with its own include loads alongside the provider’s load, and what each brings is merged. To include the messages’ images and files in the response, pass include: "files" (or an array, such as ["files", "grants"]):
See useLiveChatMessages.

Filtered / read-only queries

useLiveChatMessages is the live conversation stream and intentionally takes no filters. To fetch a filtered or read-only list of messages — for example, only messages that have replies — use useFetchManyChatMessagesWrapper, which keeps results in local state and never receives live socket traffic:
Its loadMore follows sortDir: older messages with "desc" (the default), newer ones with "asc". See useFetchManyChatMessages.

Sending Messages

useSendMessage returns an async function that sends a message and performs an optimistic insert — the message appears immediately in the UI with a temporary ID, then the temporary entry is replaced by the server-confirmed message.

Message Content Options

useSendMessage accepts a rich set of parameters:

Sending with Images and Files

When images or files is provided, the hook automatically switches to a multipart form upload. Images are processed into sizes per options (mode is required) and come back with their variants; files are stored as uploaded.
See useSendMessage.

Editing Messages

useEditMessage returns a function that takes conversationId, messageId, and updated content fields. The Redux store is updated immediately on success.
See useEditMessage.

Deleting Messages

useDeleteMessage deletes a message. The author’s delete leaves a placeholder with the sender kept (userDeletedAt set, content cleared); a group admin’s delete of another member’s message removes it (moderationStatus: "removed"), a placeholder with the sender hidden for everyone but its author. The local store shows the same placeholder once the server accepts the delete. See Deleted and removed messages.
See useDeleteMessage.

Reactions

useToggleReaction adds or removes an emoji reaction on a message. A deleted or removed message takes no new reaction: adding one answers 404 chat/message-not-found, while taking back your own still works. On such a message, offer only the reactions in userReactions, to take back. The response includes updated reactionCounts and userReactions:
See useToggleReaction.

Next Steps

Real-time

Typing indicators, unread counts, and read receipts

Threads

Threaded replies on messages