Temporary Edges
In React Flow, almost everything is built around the concepts of nodes and edges. Edges are the connections between nodes, but what if we want to create an edge that is only connected to one node? What about an "edge" not connected to any nodes at all?
This example shows how to create an "incomplete" edge when a user releases a connection line without making a connection. A ghost node is rendered where the connection line was released, and a temporary edge is added to the flow. Making use of editable edges, the user can pick the edge back up and complete the connection at which point the ghost node is removed!
Instead of connecting A directly to B in the flow, try releasing the
connection line in an empty space to create a temporary edge!
We've defined a useIncompleteEdge hook that encapsulates the logic for creating
and managing a "ghost node". It returns a number of event handlers intended to be
passed to the <ReactFlow /> component.
-
onConnectStartis called when the user starts dragging a new connection line. It updates aconnectingNodeIdref with the id of the source node. -
onConnectis called when a complete connection is made. It updates theconnectingNodeIdref tonull. -
onConnectEndis called when the user releases a connection line. This callback creates a ghost node and a temporary edge from theconnectingNodeIdto that ghost node. The temporary edge is marked asreconnectableso that the user can pick it back up and complete the connection. -
onReconnectis called when a complete reconnection is made. It updates theconnectingNodeIdref tonull. -
onReconnectEndis called when the user releases a reconnection line. This callback removes the ghost node and temporary edge. A new one may be added back whenonConnectEndis called.
This example is an adaptation of our add node on edge drop example!