Skip to main content
useConnectionManager is the recommended way to implement connection UIs. It loads the connection status with a specific user on mount and exposes named actions for every state transition: send, accept, decline, withdraw, and disconnect.

Usage Example

Parameters

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

Returns

ConnectionState
The current relationship state. One of: "none" | "pending-sent" | "pending-received" | "accepted" | "declined-sent" | "declined-received". It is the connection’s status, joined with its type while pending or declined ("pending-sent": the current user sent the request), or "none" when no connection exists.
string | null
The ID of the connection record, if one exists.
ConnectionRow | null
The connection record seen from the current user’s side, or null when there is none. See ConnectionRow.
boolean
true while the initial status is being fetched.
(props?: { message?: string }) => Promise<void>
Sends a connection request to the target user. Takes an optional message to send with the request: sendConnectionRequest({ message: "Hi!" }). Only active when status is "none" or "declined-received"; the server rejects a new request while a declined one exists between the two users (409 connection/request-declined), so in "declined-received" the call fails. When the server answers with an existing row (your request was already pending, or you were connected meanwhile), the state takes that row. When the other user sent you a request meanwhile (409 connection/request-received), the call fails and the state takes their request from the error body, so connectionStatus becomes "pending-received" and acceptConnectionRequest works.
() => Promise<void>
Accepts an incoming connection request. Only active when status is "pending-received".
() => Promise<void>
Declines an incoming connection request. Only active when status is "pending-received".
() => Promise<void>
Withdraws a pending outgoing request. Only active when status is "pending-sent".
() => Promise<void>
Removes an accepted connection. Only active when status is "accepted".
() => Promise<void>
Acts on the connection by user ID, whatever its state: withdraws a sent request, declines a received one, or disconnects an accepted connection. Does nothing when status is "none", "declined-sent" or "declined-received". After declining a received request it re-reads the status, so connection holds the declined record. Useful as a generic “remove” action when the exact state doesn’t matter.
() => Promise<void>
Re-fetches the connection status from the server.
The current user must be signed in. The hook performs no action if userId matches the authenticated user’s own ID.