Skip to main content

Overview

The live, canonical view of a conversation’s messages. Results are stored in Redux and kept in sync by ChatProvider socket events, so new messages, edits, reactions and reply-count changes appear in real time, and state is shared with useSendMessage (optimistic inserts), unread tracking and reconnect catch-up. Can be used for the main message stream or for a specific thread (by passing parentMessageId).
Requires ChatProvider in the component tree.
For a read-only or filtered query (e.g. “only messages that have replies”) that should not be touched by live socket traffic, use useFetchManyChatMessages / useFetchManyChatMessagesWrapper instead. The live hook intentionally does not take a filters prop.

Usage Example

Props

string
required
The ID of the conversation to load messages for.
string | null
When provided, loads thread replies for this parent message ID instead of the main stream. Replies are sorted ascending (oldest first); loadMore fetches newer replies.
number
Number of messages per page. Defaults to 50.
ChatMessageListIncludeParam
Fields to add to each message, as a single value or an array:
  • "files" — the files field. Left out by default to keep payloads small.
  • "grants" — the reputation-grant summary at message.grants: { total, count, viewerTotal } over positive grants. Populated by the reputation bundle; on a project without it the summary comes back zero-filled rather than missing.

Returns

ChatMessage[]
The loaded messages in ascending order (oldest first). See ChatMessage.
boolean
true while a fetch is in progress.
SublayError | null
The last load failure, or null. Cleared when the next load starts; loadMore() retries it. Shared by every mounted hook showing the same conversation (or the same thread). A SublayError.
boolean
true while loadMore() has something to fetch: a next page, or a load that failed.
() => Promise<void>
Loads the next page in reading order. For the main stream: messages older than the oldest currently loaded. For threads (parentMessageId set): the next page of newer replies. Retries the load that failed instead, when there is one (a failed first page included). Does nothing while a page is loading or when there is nothing more. Never rejects: a failure lands in error.
() => Promise<void>
Reloads from the first page. For the main stream: the latest page replaces the loaded messages, keeping optimistic messages and newer live ones; a message on the page keeps the files / grants another hook on the conversation 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. For threads: starts over from the thread’s first reply. Never rejects: a failure lands in error.

Notes

  • New messages that arrive via the socket (message:created) are added to the store automatically — no manual refetch needed. Thread replies go to their thread, never to the main stream.
  • After the socket reconnects, a thread loads the replies sent while it was offline. The main stream’s catch-up is done by ConversationProvider (see Missed Messages After a Reconnect).
  • For integration guidance, see Chat: Messages.