> ## Documentation Index
> Fetch the complete documentation index at: https://docs.sublay.io/llms.txt
> Use this file to discover all available pages before exploring further.

# Use connection manager

> Manage connection state and actions between two users

## 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](https://docs.sublay.io/v7/sdk/relationships/use-connection-manager.md).

## Usage Example

```tsx theme={null}
import { useConnectionManager } from "@sublay/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](https://docs.sublay.io/v7/sdk/relationships/use-connection-manager.md) 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.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.