React Flow logo

React Flow

A highly customizable library for building interactive node-based UIs, workflow editors, and diagrams.

npm install @xyflow/react
34.0K1.6M/weekv12.9.31.12 MBMIT115 issues
Last updated: 2025-11-13
Star history chart for xyflow/xyflow

TL;DR

The de-facto standard for building node-based applications, abstracting complex canvas logic while rendering nodes as standard React components.

Perfect for workflow builders, ETL pipelines, and architectural diagrams, offering a battle-tested 'infinite canvas' experience with zero dependencies on specific styling engines.

Why React Flow?

React Flow (now under the xyflow organization) solves the difficult problem of creating interactive, node-based interfaces on the web. It abstracts away the math and event handling required for an infinite canvas, allowing you to focus on your business logic.

  • React Component Nodes: Unlike canvas-only libraries, every node is a real React component. This means you can use inputs, dropdowns, or any other React library inside your graph nodes.
  • Interactive Primitives: Out-of-the-box support for multi-selection, zooming, panning, and keyboard shortcuts, saving hundreds of hours of boilerplate.
  • Plug-and-Play Utilities: Includes production-ready UI components like MiniMap, Controls, and Background patterns that drop directly into your application.
  • State Hook Helpers: Provides specialized hooks like useNodesState and useEdgesState to manage graph changes (dragging, connecting) idiomatically.
  • Agnostic Styling: It doesn't force a specific CSS-in-JS library on you; styling is handled via standard CSS or Tailwind, making it easy to match your design system.

Code Snippet

React Flow manages the graph state with hooks that handle user interactions like dragging nodes or connecting edges automatically.

import { useCallback } from 'react';
import {
  ReactFlow,
  MiniMap,
  Controls,
  Background,
  useNodesState,
  useEdgesState,
  addEdge,
  BackgroundVariant
} from '@xyflow/react';
import '@xyflow/react/dist/style.css';

const initialNodes = [
  { id: '1', position: { x: 0, y: 0 }, data: { label: 'Input Node' } },
  { id: '2', position: { x: 0, y: 100 }, data: { label: 'Processor' } },
];

const initialEdges = [{ id: 'e1-2', source: '1', target: '2' }];

export default function FlowEditor() {
  const [nodes, setNodes, onNodesChange] = useNodesState(initialNodes);
  const [edges, setEdges, onEdgesChange] = useEdgesState(initialEdges);

  const onConnect = useCallback(
    (params) => setEdges((eds) => addEdge(params, eds)),
    [setEdges],
  );

  return (
    <div style={{ width: '100%', height: '500px' }}>
      <ReactFlow
        nodes={nodes}
        edges={edges}
        onNodesChange={onNodesChange}
        onEdgesChange={onEdgesChange}
        onConnect={onConnect}
      >
        <Controls />
        <MiniMap />
        <Background variant={BackgroundVariant.Dots} gap={12} size={1} />
      </ReactFlow>
    </div>
  );
}

The onNodesChange and onEdgesChange handlers automatically process drag events and selection changes, while onConnect allows you to define rules for how nodes link together.

Pros and Cons

No library is perfect; understanding the trade-offs is key to selecting the right tool.

Pros

  • Deep Customization: You can customize every aspect: nodes, edges, connection lines, and handles are all swappable React components.
  • Documentation Quality: Widely regarded as having some of the best interactive documentation and examples in the React ecosystem.
  • Performance: Handles hundreds of nodes efficiently using virtualization techniques, ensuring smooth 60fps panning and zooming.

Cons

  • No Built-in Auto-Layout: React Flow focuses on the visual rendering; for automatic graph layout, you must integrate external libraries like dagre or elkjs.
  • Canvas Complexity: While it abstracts much complexity, building highly custom interactions (e.g., nested graphs or advanced port logic) still requires a steep learning curve.
  • DOM Heavy: Since nodes are DOM elements, extremely large graphs (thousands of visible nodes) may face performance ceilings compared to pure WebGL/Canvas solutions.

Comparison with Other Libraries

The table below outlines the positioning differences between React Flow and other visualization libraries to help you make an informed decision:

LibraryDesign PhilosophyBest ForPain Points
React FlowInteractive Editor
Focuses on manual manipulation and building tools/editors.
Workflow Builders
Visual programming, ETL tools, Diagram editors.
Manual Layout
No auto-layout engine included; requires external deps for complex sorting.
ReaflowStatic/Auto Layout
Built specifically for rendering directed acyclic graphs (DAGs) with auto-layout.
Diagram Visualization
Read-only architecture diagrams or simple flows.
Rigidity
Less flexibility for manual dragging or custom "free-form" canvas experiences.
Visx (Network)Low-level Primitives
A collection of D3-based visualization primitives.
Custom Viz
When you need total control over the rendering layer (SVG/Canvas).
High Boilerplate
You have to build the entire interaction layer (zoom/pan/drag) yourself.

Ecosystem & Extensions

The @xyflow/react ecosystem is robust, offering advanced features for professional applications:

  • Pro Platform: A subscription service offering advanced examples (collaborative editing, auto-layout, undo/redo).
  • Svelte Flow: The official port for Svelte developers, maintaining API consistency.
  • UseGesture: While not a direct plugin, it is heavily used alongside React Flow for advanced interaction patterns.