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 connectionsdeleteConnection
: 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
Returns
Promise
<void
>
Throws
When used outside of ConnectionsProvider
Example
tsx123456789101112131415161718192021222324252627282930313233343536373839404142import { 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><buttononClick={() => handleDeleteConnection(connection)}className="delete-button">Delete Connection</button></div>))}{connections.length === 0 && (<p>No connections established. Create a connection to get started.</p>)}</div>);}