Skip to main content

Overview

Returns an async function that creates a direct (1:1) conversation with a given user. If a direct conversation between the two users already exists on the server, it is returned rather than creating a duplicate. The conversation is also stored in Redux state.
Requires ChatProvider in the component tree.

Usage Example

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

function UserCard({ userId }: { userId: string }) {
  const createDirect = useCreateDirectConversation();

  const handleMessage = async () => {
    const conversation = await createDirect({ userId });
    // Navigate to the conversation, e.g. router.push(`/chat/${conversation.id}`)
  };

  return <button onClick={handleMessage}>Message</button>;
}

Parameters

The hook returns a function. That function accepts:
userId
string
required
The ID of the user to start a conversation with.

Returns

Conversation
Conversation
The created or retrieved direct Conversation.

Notes