Skip to main content

Overview

High-level hook that fetches the connection status between the current user and a target user on mount, then exposes named action functions for every state transition. The appropriate action for each state is enforced — only valid transitions can fire. For integration guidance and a full example, see Relationships — useConnectionManager.

Usage Example

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

function ConnectionControls({ userId }: { userId: string }) {
  const { connectionStatus, isLoading, sendConnectionRequest, acceptConnectionRequest } =
    useConnectionManager({ userId });

  if (isLoading) return null;
  if (connectionStatus === "none")
    return <button onClick={() => sendConnectionRequest()}>Connect</button>;
  if (connectionStatus === "pending-received")
    return <button onClick={acceptConnectionRequest}>Accept</button>;
  return null;
}

Parameters

userId
string
required
The ID of the user whose connection relationship to manage.

Returns

connectionStatus
ConnectionStatus
One of: "none" | "pending-sent" | "pending-received" | "connected" | "declined-sent" | "declined-received".
connectionId
string | null
The active connection record ID, or null if there is no connection.
connectionData
object
Metadata about the current connection state (timestamps, direction). See useConnectionManager SDK page for full shape.
isLoading
boolean
true while the initial status is being fetched.
sendConnectionRequest
(message?: string) => Promise<void>
Sends a connection request. Only active when status is "none" or "declined-received".
acceptConnectionRequest
() => Promise<void>
Accepts an incoming request. Only active when status is "pending-received".
declineConnectionRequest
() => Promise<void>
Declines an incoming request. Only active when status is "pending-received".
withdrawConnectionRequest
() => Promise<void>
Withdraws a sent request. Only active when status is "pending-sent".
disconnectUser
() => Promise<void>
Removes an established connection. Only active when status is "connected".
removeConnectionSmart
() => Promise<void>
Removes the connection in any state using the user ID (withdraw, disconnect, or decline depending on state).
refreshConnectionStatus
() => Promise<void>
Re-fetches connection status from the server.