<ReactFlow />
The <ReactFlow /> component is the heart of your React Flow application. It
renders your nodes and edges, handles user interaction, and can manage its own
state if used as an uncontrolled flow.
import { ReactFlow } from '@xyflow/react'
export default function Flow() {
return <ReactFlow
nodes={...}
edges={...}
onNodesChange={...}
...
/>
}This component takes a lot of different props, most of which are optional. We’ve tried to document them in groups that make sense to help you find your way.
Common props
These are the props you will most commonly use when working with React Flow. If you are working with a controlled flow with custom nodes, you will likely use almost all of these!
| Name | Type | Default |
|---|---|---|
width | numberSets a fixed width for the flow. | |
height | numberSets a fixed height for the flow. | |
nodes | Node[]An array of nodes to render in a controlled flow. | [] |
edges | Edge[]An array of edges to render in a controlled flow. | [] |
defaultNodes | Node[]The initial nodes to render in an uncontrolled flow. | |
defaultEdges | Edge[]The initial edges to render in an uncontrolled flow. | |
paneClickDistance | numberDistance that the mouse can move between mousedown/up that will trigger a click. | 0 |
nodeClickDistance | numberDistance that the mouse can move between mousedown/up that will trigger a click. | 0 |
nodeTypes | NodeTypesCustom node types to be available in a flow. React Flow matches a node’s type to a component in the | is correct
{
input: InputNode,
default: DefaultNode,
output: OutputNode,
group: GroupNode
} |
edgeTypes | EdgeTypesCustom edge types to be available in a flow. React Flow matches an edge’s type to a component in the | is correct
{
default: BezierEdge,
straight: StraightEdge,
step: StepEdge,
smoothstep: SmoothStepEdge,
simplebezier: SimpleBezier
} |
nodeOrigin | NodeOriginThe origin of the node to use when placing it in the flow or looking up its | [0, 0] |
proOptions | ProOptionsBy default, we render a small attribution in the corner of your flows that links back to the project. Anyone is free to remove this attribution whether they’re a Pro subscriber or not but we ask that you take a quick look at our https://reactflow.dev/learn/troubleshooting/remove-attribution removing attribution guide before doing so. | |
nodeDragThreshold | numberWith a threshold greater than zero you can delay node drag events. If threshold equals 1, you need to drag the node 1 pixel before a drag event is fired. 1 is the default value, so clicks don’t trigger drag events. | 1 |
colorMode | ColorModeControls color scheme used for styling the flow. | 'light' |
debug | booleanIf set | false |
...props | Omit<DetailedHTMLProps<HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "onError"> |
Viewport props
| Name | Type | Default |
|---|---|---|
defaultViewport | ViewportSets the initial position and zoom of the viewport. If a default viewport is provided but
| { x: 0, y: 0, zoom: 1 } |
viewport | ViewportWhen you pass a | |
onViewportChange | (viewport: Viewport) => voidUsed when working with a controlled viewport for updating the user viewport state. | |
fitView | booleanWhen | |
fitViewOptions | FitViewOptionsWhen you typically call | |
minZoom | numberMinimum zoom level. | 0.5 |
maxZoom | numberMaximum zoom level. | 2 |
snapToGrid | booleanWhen enabled, nodes will snap to the grid when dragged. | |
snapGrid | SnapGridIf | |
onlyRenderVisibleElements | booleanYou can enable this optimisation to instruct React Flow to only render nodes and edges that would be visible in the viewport. This might improve performance when you have a large number of nodes and edges but also adds an overhead. | false |
translateExtent | CoordinateExtentBy default, the viewport extends infinitely. You can use this prop to set a boundary. The first pair of coordinates is the top left boundary and the second pair is the bottom right. | [[-∞, -∞], [+∞, +∞]] |
nodeExtent | CoordinateExtentBy default, nodes can be placed on an infinite flow. You can use this prop to set a boundary. The first pair of coordinates is the top left boundary and the second pair is the bottom right. | |
preventScrolling | booleanDisabling this prop will allow the user to scroll the page even when their pointer is over the flow. | true |
attributionPosition | PanelPositionBy default, React Flow will render a small attribution in the bottom right corner of the flow. You can use this prop to change its position in case you want to place something else there. | 'bottom-right' |
Edge props
| Name | Type | Default |
|---|---|---|
elevateEdgesOnSelect | booleanEnabling this option will raise the z-index of edges when they are selected. | |
defaultMarkerColor | stringColor of edge markers. | '#b1b1b7' |
defaultEdgeOptions | DefaultEdgeOptionsDefaults to be applied to all new edges that are added to the flow. Properties on a new edge will override these defaults if they exist. | |
reconnectRadius | numberThe radius around an edge connection that can trigger an edge reconnection. | 10 |
edgesReconnectable | booleanWhether edges can be updated once they are created. When both this prop is | true |
Event handlers
It’s important to remember to define any event handlers outside of your
component or using React’s useCallback hook. If you don’t, this can cause
React Flow to enter an infinite re-render loop!
General Events
| Name | Type | Default |
|---|---|---|
onError | OnErrorOccasionally something may happen that causes React Flow to throw an error. Instead of exploding your application, we log a message to the console and then call this event handler. You might use it for additional logging or to show a message to the user. | |
onInit | OnInit<Node, Edge>The | |
onDelete | OnDelete<Node, Edge>This event handler gets called when a node or edge is deleted. | |
onBeforeDelete | OnBeforeDelete<Node, Edge>This handler is called before nodes or edges are deleted, allowing the deletion to be aborted
by returning |
Node Events
| Name | Type | Default |
|---|---|---|
onNodeClick | NodeMouseHandler<Node>This event handler is called when a user clicks on a node. | |
onNodeDoubleClick | NodeMouseHandler<Node>This event handler is called when a user double-clicks on a node. | |
onNodeDragStart | OnNodeDrag<Node>This event handler is called when a user starts to drag a node. | |
onNodeDrag | OnNodeDrag<Node>This event handler is called when a user drags a node. | |
onNodeDragStop | OnNodeDrag<Node>This event handler is called when a user stops dragging a node. | |
onNodeMouseEnter | NodeMouseHandler<Node>This event handler is called when mouse of a user enters a node. | |
onNodeMouseMove | NodeMouseHandler<Node>This event handler is called when mouse of a user moves over a node. | |
onNodeMouseLeave | NodeMouseHandler<Node>This event handler is called when mouse of a user leaves a node. | |
onNodeContextMenu | NodeMouseHandler<Node>This event handler is called when a user right-clicks on a node. | |
onNodesDelete | OnNodesDelete<Node>This event handler gets called when a node is deleted. | |
onNodesChange | OnNodesChange<Node>Use this event handler to add interactivity to a controlled flow. It is called on node drag, select, and move. |
Edge Events
| Name | Type | Default |
|---|---|---|
onEdgeClick | (event: MouseEvent<Element, MouseEvent>, edge: Edge) => voidThis event handler is called when a user clicks on an edge. | |
onEdgeDoubleClick | EdgeMouseHandler<Edge>This event handler is called when a user double-clicks on an edge. | |
onEdgeMouseEnter | EdgeMouseHandler<Edge>This event handler is called when mouse of a user enters an edge. | |
onEdgeMouseMove | EdgeMouseHandler<Edge>This event handler is called when mouse of a user moves over an edge. | |
onEdgeMouseLeave | EdgeMouseHandler<Edge>This event handler is called when mouse of a user leaves an edge. | |
onEdgeContextMenu | EdgeMouseHandler<Edge>This event handler is called when a user right-clicks on an edge. | |
onReconnect | OnReconnect<Edge>This handler is called when the source or target of a reconnectable edge is dragged from the current node. It will fire even if the edge’s source or target do not end up changing. You can use the | |
onReconnectStart | (event: MouseEvent<Element, MouseEvent>, edge: Edge, handleType: HandleType) => voidThis event fires when the user begins dragging the source or target of an editable edge. | |
onReconnectEnd | (event: MouseEvent | TouchEvent, edge: Edge, handleType: HandleType) => voidThis event fires when the user releases the source or target of an editable edge. It is called even if an edge update does not occur. | |
onEdgesDelete | OnEdgesDelete<Edge>This event handler gets called when an edge is deleted. | |
onEdgesChange | OnEdgesChange<Edge>Use this event handler to add interactivity to a controlled flow. It is called on edge select and remove. |
Connection Events
| Name | Type | Default |
|---|---|---|
onConnect | OnConnectWhen a connection line is completed and two nodes are connected by the user, this event fires with the new connection. You can use the | |
onConnectStart | OnConnectStartThis event handler gets called when a user starts to drag a connection line. | |
onConnectEnd | OnConnectEndThis callback will fire regardless of whether a valid connection could be made or not. You can
use the second | |
onClickConnectStart | OnConnectStart | |
onClickConnectEnd | OnConnectEnd | |
isValidConnection | IsValidConnection<Edge>This callback can be used to validate a new connection If you return |
Pane Events
| Name | Type | Default |
|---|---|---|
onMove | OnMoveThis event handler is called while the user is either panning or zooming the viewport. | |
onMoveStart | OnMoveThis event handler is called when the user begins to pan or zoom the viewport. | |
onMoveEnd | OnMoveThis event handler is called when panning or zooming viewport movement stops.
If the movement is not user-initiated, the event parameter will be | |
onPaneClick | (event: MouseEvent<Element, MouseEvent>) => voidThis event handler gets called when user clicks inside the pane. | |
onPaneContextMenu | (event: MouseEvent | React.MouseEvent<Element, MouseEvent>) => voidThis event handler gets called when user right clicks inside the pane. | |
onPaneScroll | (event?: WheelEvent<Element> | undefined) => voidThis event handler gets called when user scroll inside the pane. | |
onPaneMouseMove | (event: MouseEvent<Element, MouseEvent>) => voidThis event handler gets called when mouse moves over the pane. | |
onPaneMouseEnter | (event: MouseEvent<Element, MouseEvent>) => voidThis event handler gets called when mouse enters the pane. | |
onPaneMouseLeave | (event: MouseEvent<Element, MouseEvent>) => voidThis event handler gets called when mouse leaves the pane. |
Selection Events
| Name | Type | Default |
|---|---|---|
onSelectionChange | OnSelectionChangeFunc<Node, Edge>This event handler gets called when a user changes group of selected elements in the flow. | |
onSelectionDragStart | SelectionDragHandler<Node>This event handler gets called when a user starts to drag a selection box. | |
onSelectionDrag | SelectionDragHandler<Node>This event handler gets called when a user drags a selection box. | |
onSelectionDragStop | SelectionDragHandler<Node>This event handler gets called when a user stops dragging a selection box. | |
onSelectionStart | (event: MouseEvent<Element, MouseEvent>) => void | |
onSelectionEnd | (event: MouseEvent<Element, MouseEvent>) => void | |
onSelectionContextMenu | (event: MouseEvent<Element, MouseEvent>, nodes: Node[]) => voidThis event handler is called when a user right-clicks on a node selection. |
Interaction props
| Name | Type | Default |
|---|---|---|
nodesDraggable | booleanControls whether all nodes should be draggable or not. Individual nodes can override this
setting by setting their | true |
nodesConnectable | booleanControls whether all nodes should be connectable or not. Individual nodes can override this
setting by setting their | true |
nodesFocusable | booleanWhen | true |
edgesFocusable | booleanWhen | true |
elementsSelectable | booleanWhen | true |
autoPanOnConnect | booleanWhen | true |
autoPanOnNodeDrag | booleanWhen | true |
autoPanSpeed | numberThe speed at which the viewport pans while dragging a node or a selection box. | 15 |
panOnDrag | boolean | number[]Enabling this prop allows users to pan the viewport by clicking and dragging. You can also set this prop to an array of numbers to limit which mouse buttons can activate panning. | true |
selectionOnDrag | booleanSelect multiple elements with a selection box, without pressing down | false |
selectionMode | SelectionModeWhen set to | 'full' |
panOnScroll | booleanControls if the viewport should pan by scrolling inside the container. Can be limited to a specific direction with | false |
panOnScrollSpeed | numberControls how fast viewport should be panned on scroll. Use together with | 0.5 |
panOnScrollMode | PanOnScrollModeThis prop is used to limit the direction of panning when The | "free" |
zoomOnScroll | booleanControls if the viewport should zoom by scrolling inside the container. | true |
zoomOnPinch | booleanControls if the viewport should zoom by pinching on a touch screen. | true |
zoomOnDoubleClick | booleanControls if the viewport should zoom by double-clicking somewhere on the flow. | true |
selectNodesOnDrag | booleanIf | true |
elevateNodesOnSelect | booleanEnabling this option will raise the z-index of nodes when they are selected. | true |
connectOnClick | booleanThe If you set this option to | true |
connectionMode | ConnectionModeA loose connection mode will allow you to connect handles with differing types, including source-to-source connections. However, it does not support target-to-target connections. Strict mode allows only connections between source handles and target handles. | 'strict' |
Connection line props
| Name | Type | Default |
|---|---|---|
connectionLineStyle | CSSPropertiesStyles to be applied to the connection line. | |
connectionLineType | ConnectionLineTypeThe type of edge path to use for connection lines. Although created edges can be of any type, React Flow needs to know what type of path to render for the connection line before the edge is created! | ConnectionLineType.Bezier |
connectionRadius | numberThe radius around a handle where you drop a connection line to create a new edge. | 20 |
connectionLineComponent | ConnectionLineComponent<Node>React Component to be used as a connection line. | |
connectionLineContainerStyle | CSSPropertiesStyles to be applied to the container of the connection line. |
Keyboard props
React Flow let’s you pass in a few different keyboard shortcuts as another way to interact with your flow. We’ve tried to set up sensible defaults like using backspace to delete any selected nodes or edges, but you can use these props to set your own.
To disable any of these shortcuts, pass in null to the prop you want to
disable.
Style props
Applying certain classes to elements rendered inside the canvas will change how interactions are handled. These props let you configure those class names if you need to.
Notes
- The props of this component get exported as
ReactFlowProps