Skip to content

Use Connection

OnConnectionChange reports the connection being drawn on every move - where it started, where the pointer is, whether letting go would connect and, if not, why the nearest handle refuses - and null once it ends. It is React Flow's useConnection, for hints or panels that follow the drag.

Drag from here
Node B
Node C
bit Blow

Try it

  • Drag from the handle under "Drag from here" and move around: the panel under the canvas updates on every move, with the pointer position in flow coordinates.
  • Bring the pointer near the top handle of Node B or Node C: IsValid turns to yes before you are exactly on it, because a release that close would snap to it.
  • Bring it near Node B's bottom handle instead: Rejection says SameHandleType - a source cannot be joined to a source. Connect to Node B once and approach its top handle again for Duplicate.
  • Let go or press Escape: the canvas sends a final null, and the panel says how many updates the gesture took. Drag from a target handle (the top of B or C) to see FromHandleType change.

How it works

  • OnConnectionChange is an EventCallback<BlowConnectionLineContext?>: raised when a connection starts, on every pointer move while it is drawn, and once with null when it ends, however it ends.
  • FromNode, FromHandle and FromHandleType name the handle the drag started at; From is its anchor and FromPosition its side. To is the pointer, in flow coordinates, and ToPosition the side the line arrives on - the opposite of FromPosition, for drawing a path.
  • IsValid is true when releasing now would connect: the pointer is over a handle that accepts the connection, or within ConnectionRadius (20 screen pixels) of one.
  • Rejection is the BlowConnectionRejection of the handle the line ends at - the one under the pointer, or the nearest within snapping distance - and None when it would accept, or when no handle is near. The sentence beside it is BlowAriaLabels.Default.ConnectionRejected, what a screen reader hears when such a drop is refused.
  • The same context is what a ConnectionLineTemplate draws from (see Custom Connection Line). Each update re-renders this page, so keep the handler light.
An unhandled error has occurred. Reload 🗙