React Flow
React Flow (@xyflow/react) is a library for building node-based graphs, workflow editors, and interactive diagrams. It provides a highly customizable framework for creating visual programming interfaces, process flows, and network visualizations.
Quick Start
Installation
Basic Setup
Core Concepts
Nodes
Nodes are the building blocks of the graph. Each node has:
id: Unique identifiertype: Node type (built-in or custom)position: { x, y } coordinatesdata: Custom data object
Built-in node types:
default: Standard nodeinput: No target handlesoutput: No source handlesgroup: Container for other nodes
Edges
Edges connect nodes. Each edge requires:
id: Unique identifiersource: Source node IDtarget: Target node ID
Built-in edge types:
default: Bezier curvestraight: Straight linestep: Orthogonal with sharp cornerssmoothstep: Orthogonal with rounded corners
Handles
Handles are connection points on nodes. Use Position enum for placement:
Available positions: Position.Top, Position.Right, Position.Bottom, Position.Left
State Management
Controlled Flow
Use state hooks for full control:
useReactFlow Hook
Access the React Flow instance for programmatic control:
Custom Nodes
Define custom nodes using NodeProps<T> with typed data:
Register with nodeTypes:
Key Patterns
- Multiple Handles: Use
idprop andstylefor positioning - Dynamic Handles: Call
useUpdateNodeInternals([nodeId])after adding/removing handles - Interactive Elements: Add
className="nodrag"to prevent dragging on inputs/buttons
See Custom Nodes Reference for detailed patterns including styling, aviation map pins, and dynamic handles.
Custom Edges
Define custom edges using EdgeProps<T> and path utilities:
Path Utilities
getBezierPath()- Smooth curvesgetStraightPath()- Straight linesgetSmoothStepPath()- Orthogonal with rounded cornersgetSmoothStepPath({ borderRadius: 0 })- Orthogonal with sharp corners (step edge)
All return [path, labelX, labelY, offsetX, offsetY].
Interactive Labels
Use EdgeLabelRenderer for HTML-based labels with pointer events:
See Custom Edges Reference for animated edges, time labels, and SVG text patterns.
Viewport Control
Use useReactFlow() hook for programmatic viewport control:
See Viewport Reference for save/restore state, controlled viewport, and coordinate transformations.
Events
React Flow provides comprehensive event handling:
Node Events
Edge and Connection Events
Selection and Viewport Events
See Events Reference for complete event catalog including validation, deletion, and error handling.
Common Patterns
Preventing Drag/Pan
Connection Validation
Adding Nodes on Click
Updating Node Data
Provider Pattern
Wrap the app with ReactFlowProvider when using useReactFlow() outside the flow:
Implementation gates
Use these sequenced checks before treating an integration as done (they target common footguns, not style preferences).
- CSS in the bundle — Ensure
import '@xyflow/react/dist/style.css'runs in the app (entry or layout). Pass: nodes and edges have expected default styling; handles are visible and interactable. - Stable
nodeTypes/edgeTypes— Do not pass a fresh object literal every render; define maps outside the component or memoize withuseMemoand correct deps. Pass: no remount flicker or “maximum update depth” / runaway updates when only selection or viewport changes. - Provider boundary — Components that call
useReactFlow()must be descendants ofReactFlowProvider, and the flow must actually mount. Pass: no missing-context error at runtime; programmatic APIs (fitView, etc.) work where expected.
Reference Files
For detailed implementation patterns, see:
- Custom Nodes - NodeProps typing, Handle component, dynamic handles, styling patterns
- Custom Edges - EdgeProps typing, path utilities, EdgeLabelRenderer, animated edges
- Viewport - useReactFlow methods, fitView options, coordinate conversion
- Events - Node/edge/connection events, selection handling, viewport changes


