Skip to main content

Overview

Returns a function that fetches the full connection status between the current authenticated user and a target user. Returns a discriminated union based on the current state: "none", "pending", "connected", or "declined". useConnectionManager calls this automatically on mount. Use this hook directly when you need one-off status checks without managing state.

Usage Example

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

function ProfilePage({ userId }: { userId: string }) {
  const fetchConnectionStatus = useFetchConnectionStatus();

  useEffect(() => {
    fetchConnectionStatus({ userId }).then((status) => {
      console.log(status.status); // "none" | "pending" | "connected" | "declined"
    });
  }, [userId]);
}

Parameters

The hook returns a function. That function accepts:
userId
string
required
The ID of the user to check. Cannot be the current user’s own ID.

Returns

Returns a ConnectionStatusResponse — a discriminated union based on status: When status === "none":
status
"none"
No connection exists.
When status === "pending":
status
"pending"
A connection request is pending.
type
"sent" | "received"
Direction from the current user’s perspective.
connectionId
string
The connection record ID.
createdAt
string
ISO timestamp when the request was created.
When status === "connected":
status
"connected"
Connection is established.
connectionId
string
The connection record ID.
connectedAt
string
ISO timestamp when the connection was established.
requestedAt
string
ISO timestamp when the request was originally sent.
When status === "declined":
status
"declined"
A connection request was declined.
type
"sent" | "received"
Direction of the original request.
connectionId
string
The connection record ID.
respondedAt
string
ISO timestamp when the request was declined.