Skip to main content

Overview

Fetches the full details of a single conversation by ID and provides update and deleteConversation actions. The conversation is loaded once on mount if it is not already in Redux state, and kept in sync by conversation:updated socket events.
Requires ChatProvider in the component tree.

Usage Example

import { useConversation } from "@replyke/react-js";

function ConversationHeader({ conversationId }: { conversationId: string }) {
  const { conversation, loading, update, deleteConversation } = useConversation({
    conversationId,
  });

  if (loading || !conversation) return <div>Loading...</div>;

  return (
    <div>
      <h2>{conversation.name ?? "Direct Message"}</h2>
      <button onClick={() => update({ name: "Renamed Group" })}>Rename</button>
      <button onClick={deleteConversation}>Delete</button>
    </div>
  );
}

Props

conversationId
string
required
The ID of the conversation to fetch and manage.

Returns

conversation
Conversation | null
The full Conversation object, or null while loading or if not found.
loading
boolean
true while the initial fetch is in progress.
update
(params: { name?: string; description?: string; avatarFileId?: string | null; postingPermission?: 'members' | 'admins' }) => Promise<Conversation | undefined>
Updates the conversation. Dispatches the updated conversation to Redux on success. conversationId is already bound from the hook props and should not be passed here.
FieldTypeDescription
namestringNew conversation name
descriptionstringNew description
avatarFileIdstring | nullFile ID for the avatar image
postingPermission'members' | 'admins'Who can post (space chats only)
deleteConversation
() => Promise<void>
Deletes the conversation. Does not update local Redux state — the caller is responsible for navigating away or removing the conversation from local lists.

Notes