Skip to Content
ReferenceHooks

useNodeConnections()

Source on GitHub

This hook returns an array of connections on a specific node, handle type (‘source’, ‘target’) or handle ID.

import { useNodeConnections } from '@xyflow/react'; export default function () { const connections = useNodeConnections({ handleType: 'target', handleId: 'my-handle', }); return ( <div>There are currently {connections.length} incoming connections!</div> ); }

Signature

Parameters:
NameTypeDefault
[0]?.idstring

ID of the node, filled in automatically if used inside custom node.

[0]?.handleTypeHandleType

What type of handle connections do you want to observe?

[0]?.handleIdstring

Filter by handle id (this is only needed if the node has multiple handles of the same type).

[0]?.onConnect(connections: Connection[]) => void

Gets called when a connection is established.

[0]?.onDisconnect(connections: Connection[]) => void

Gets called when a connection is removed.

Returns:
NodeConnection[]

An array with connections.

Last updated on