ExamplesInteraction

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.

export default function App() {
  const data: string = "world"

  return <h1>Hello {data}</h1>
}

Read-only

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:

You can see many of these events in use in our add node on edge drop and temporary edges examples!