useHandleConnections()
WARNING
useHandleConnectionsis deprecated in favor of the more capable useNodeConnections.
This hook returns an array connections on a specific handle or handle type.
import { useHandleConnections } from '@xyflow/react';
export default function () {
const connections = useHandleConnections({ type: 'target', id: 'my-handle' });
return (
<div>There are currently {connections.length} incoming connections!</div>
);
}Signature
Hook to check if a
Parameters
[0].type: 'source' | 'target'What type of handle connections do you want to observe?[0].id?: string | nullThe handle id (this is only needed if the node has multiple handles of the same type).[0].nodeId?: stringIf node id is not provided, the node id from theNodeIdContextis used.[0].onConnect?: (connections: Connection[]) => voidGets called when a connection is established.[0].onDisconnect?: (connections: Connection[]) => voidGets called when a connection is removed.
Returns
HandleConnection[]