Skip to main content

Overview

useFetchManyChatMessagesWrapper is a stateful wrapper around useFetchManyChatMessages that manages the message list and cursor pagination for you. It keeps results in local component state — not Redux — and never receives socket updates. Use it for a read-only or filtered list of messages that should not be touched by live traffic — for example, a “messages with replies” panel, an admin/moderation view, or any custom message list outside the live conversation stream. For the live canonical conversation view, use useLiveChatMessages instead.
This is a point-in-time query: it does not auto-update from socket events. Call refetch (e.g. on a refresh button, or on a socket signal of your choosing) to pick up new matches. It does not require ChatProvider.

Usage Example

import { useFetchManyChatMessagesWrapper } from "@sublay/react-js";

function MessagesWithReplies({ conversationId }: { conversationId: string }) {
  const { messages, loading, hasMore, loadMore, refetch } =
    useFetchManyChatMessagesWrapper({
      conversationId,
      filters: { hasReplies: true },
    });

  return (
    <div>
      <button onClick={refetch} disabled={loading}>Refresh</button>
      {messages.map((m) => (
        <div key={m.id}>
          {m.content} · {m.threadReplyCount} replies
        </div>
      ))}
      {hasMore && (
        <button onClick={loadMore} disabled={loading}>Load more</button>
      )}
    </div>
  );
}

Props

conversationId
string
required
The ID of the conversation to query.
parentId
string | null
Restrict to thread replies of this message.
limit
number
Page size. Defaults to 50.
sort
"asc" | "desc"
Sort by creation time. Defaults to "desc" (newest first), where loadMore fetches older messages. With "asc", loadMore fetches newer messages.
includeFiles
boolean
When true, the server populates the files field on each message.
filters
MessageFilters
Optional filters. filters.hasReplies (boolean): when true, returns only messages that have thread replies (threadReplyCount > 0); when false, only messages with none. Filters by thread replies, not quotings.
Threads are one level deep, so hasReplies: true together with parentId always yields an empty list. This wrapper exposes only messages; use the lower-level useFetchManyChatMessages if you want the notice explaining why.

Returns

messages
ChatMessage[]
The loaded messages. See ChatMessage.
loading
boolean
true while a fetch is in progress.
hasMore
boolean
true if more messages can be loaded.
loadMore
() => void
Loads the next page in the direction of sort and appends it. No-ops while loading or when there are no more pages.
refetch
() => void
Re-fetches the first page from scratch (e.g. to pick up new matches).