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

Parameters

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

Returns

ConnectionState
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 connection record ID, or null if there is no connection.
ConnectionRow | null
The connection record seen from the current user’s side (user is the target user), or null if there is none. See ConnectionRow.
boolean
true while the initial status is being fetched.
(props?: { message?: string }) => Promise<void>
Sends a connection request. 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 request. Only active when status is "pending-received".
() => Promise<void>
Declines an incoming request. Only active when status is "pending-received".
() => Promise<void>
Withdraws a sent 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.
() => Promise<void>
Re-fetches connection status from the server.