Function: useConnections()

typescript
1
useConnections(): object

Defined in: hooks/index.ts:638

Hook for accessing DID connection context and operations.

Provides functionality for managing established DID connections (relationships between DIDs) including viewing and deleting connections. This hook must be used within a ConnectionsProvider.

Returns

Connections context containing:

  • connections: Array of all established DID-to-DID connections
  • deleteConnection: Async function to permanently delete a connection

connections

typescript
1
connections: DIDPair[]

Array of established DID connections

deleteConnection()

typescript
1
deleteConnection: (connection) => Promise<void>

Function to delete a connection

Parameters

connection

DIDPair

Returns

Promise<void>

Throws

When used outside of ConnectionsProvider

Example

tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import { useConnections } from '@trust0/identus-react/hooks';
function ConnectionManager() {
const { connections, deleteConnection } = useConnections();
const handleDeleteConnection = async (connection) => {
if (window.confirm('Are you sure you want to delete this connection?')) {
try {
await deleteConnection(connection);
console.log('Connection deleted successfully');
} catch (error) {
console.error('Failed to delete connection:', error);
}
}
};
return (
<div>
<h3>My Connections ({connections.length})</h3>
{connections.map((connection, index) => (
<div key={index} className="connection-card">
<h4>Connection {index + 1}</h4>
<p>Host: {connection.host.toString()}</p>
<p>Receiver: {connection.receiver.toString()}</p>
<p>Name: {connection.name || 'Unnamed Connection'}</p>
<button
onClick={() => handleDeleteConnection(connection)}
className="delete-button"
>
Delete Connection
</button>
</div>
))}
{connections.length === 0 && (
<p>No connections established. Create a connection to get started.</p>
)}
</div>
);
}