Connection Events
React Flow emits different events during the connection process that you can use to update your UI or your flow in different ways. The example below demonstrates which events are fired and when.
For a new connection created by dragging from a handle, the following events are called in order:
-
onConnectStart
is called with the mouse event and an object containing the source node, potentially the source handle id, and the handle type. -
onConnect
is only called when the connection is released on a handle that is connectable. It is called with a complete connection object containing the source and target node, and the source and target handle ids if present. -
onConnectEnd
is called when a connection is released, regardless of whether it was successful or not. It is called with the mouse event.
When an edge is reconnected by dragging an existing edge, the following events are called in order:
-
onReconnectStart
is called when a reconnectable edge is picked up. It is called with the mouse event, the edge object that is being reconnected, and the type of the stable handle. -
onConnectStart
is called as above. -
onReconnect
is called when the edge is released on a handle that is reconnectable. It is called with the old edge object and the new connection object. -
onConnectEnd
is called as above. -
onReconnectEnd
is called when the edge is released, regardless of whether the reconnection whas successful or not. It is called with the mouse event, the edge that was picked up, and the type of the stable handle.
You can see many of these events in use in our add node on edge drop and temporary edges examples!