← Back to Skills Marketplace
anderskev

React Flow

by Kevin Anderson · GitHub ↗ · v1.1.1 · MIT-0
cross-platform ✓ Security Clean
153
Downloads
0
Stars
1
Active Installs
2
Versions
Install in OpenClaw
/install react-flow
Description
React Flow (@xyflow/react) for workflow visualization with custom nodes and edges. Use when building graph visualizations, creating custom workflow nodes, im...
README (SKILL.md)

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

pnpm add @xyflow/react

Basic Setup

import { ReactFlow, Node, Edge, Background, Controls, MiniMap } from '@xyflow/react';
import '@xyflow/react/dist/style.css';

const initialNodes: Node[] = [
  {
    id: '1',
    type: 'input',
    data: { label: 'Input Node' },
    position: { x: 250, y: 5 },
  },
  {
    id: '2',
    data: { label: 'Default Node' },
    position: { x: 100, y: 100 },
  },
  {
    id: '3',
    type: 'output',
    data: { label: 'Output Node' },
    position: { x: 400, y: 100 },
  },
];

const initialEdges: Edge[] = [
  { id: 'e1-2', source: '1', target: '2', animated: true },
  { id: 'e2-3', source: '2', target: '3' },
];

function Flow() {
  return (
    \x3Cdiv style={{ width: '100vw', height: '100vh' }}>
      \x3CReactFlow nodes={initialNodes} edges={initialEdges}>
        \x3CBackground />
        \x3CControls />
        \x3CMiniMap />
      \x3C/ReactFlow>
    \x3C/div>
  );
}

export default Flow;

Core Concepts

Nodes

Nodes are the building blocks of the graph. Each node has:

  • id: Unique identifier
  • type: Node type (built-in or custom)
  • position: { x, y } coordinates
  • data: Custom data object
import { Node } from '@xyflow/react';

const node: Node = {
  id: 'node-1',
  type: 'default',
  position: { x: 100, y: 100 },
  data: { label: 'Node Label' },
  style: { background: '#D6D5E6' },
  className: 'custom-node',
};

Built-in node types:

  • default: Standard node
  • input: No target handles
  • output: No source handles
  • group: Container for other nodes

Edges

Edges connect nodes. Each edge requires:

  • id: Unique identifier
  • source: Source node ID
  • target: Target node ID
import { Edge } from '@xyflow/react';

const edge: Edge = {
  id: 'e1-2',
  source: '1',
  target: '2',
  type: 'smoothstep',
  animated: true,
  label: 'Edge Label',
  style: { stroke: '#fff', strokeWidth: 2 },
};

Built-in edge types:

  • default: Bezier curve
  • straight: Straight line
  • step: Orthogonal with sharp corners
  • smoothstep: Orthogonal with rounded corners

Handles

Handles are connection points on nodes. Use Position enum for placement:

import { Handle, Position } from '@xyflow/react';

\x3CHandle type="target" position={Position.Top} />
\x3CHandle type="source" position={Position.Bottom} />

Available positions: Position.Top, Position.Right, Position.Bottom, Position.Left

State Management

Controlled Flow

Use state hooks for full control:

import { useNodesState, useEdgesState, addEdge, OnConnect } from '@xyflow/react';
import { useCallback } from 'react';

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

  const onConnect: OnConnect = useCallback(
    (connection) => setEdges((eds) => addEdge(connection, eds)),
    [setEdges]
  );

  return (
    \x3CReactFlow
      nodes={nodes}
      edges={edges}
      onNodesChange={onNodesChange}
      onEdgesChange={onEdgesChange}
      onConnect={onConnect}
    />
  );
}

useReactFlow Hook

Access the React Flow instance for programmatic control:

import { useReactFlow } from '@xyflow/react';

function FlowControls() {
  const {
    getNodes,
    getEdges,
    setNodes,
    setEdges,
    addNodes,
    addEdges,
    deleteElements,
    fitView,
    zoomIn,
    zoomOut,
    getNode,
    getEdge,
    updateNode,
    updateEdge,
  } = useReactFlow();

  return (
    \x3Cbutton onClick={() => fitView()}>Fit View\x3C/button>
  );
}

Custom Nodes

Define custom nodes using NodeProps\x3CT> with typed data:

import { NodeProps, Node, Handle, Position } from '@xyflow/react';

export type CustomNode = Node\x3C{ label: string; status: 'active' | 'inactive' }, 'custom'>;

function CustomNodeComponent({ data, selected }: NodeProps\x3CCustomNode>) {
  return (
    \x3Cdiv className={`px-4 py-2 ${selected ? 'ring-2' : ''}`}>
      \x3CHandle type="target" position={Position.Top} />
      \x3Cdiv className="font-bold">{data.label}\x3C/div>
      \x3CHandle type="source" position={Position.Bottom} />
    \x3C/div>
  );
}

Register with nodeTypes:

const nodeTypes: NodeTypes = { custom: CustomNodeComponent };
\x3CReactFlow nodeTypes={nodeTypes} />

Key Patterns

  • Multiple Handles: Use id prop and style for 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\x3CT> and path utilities:

import { BaseEdge, EdgeProps, getBezierPath } from '@xyflow/react';

export type CustomEdge = Edge\x3C{ status: 'normal' | 'error' }, 'custom'>;

function CustomEdgeComponent(props: EdgeProps\x3CCustomEdge>) {
  const [edgePath] = getBezierPath(props);

  return (
    \x3CBaseEdge
      id={props.id}
      path={edgePath}
      style={{ stroke: props.data?.status === 'error' ? '#ef4444' : '#64748b' }}
    />
  );
}

Path Utilities

  • getBezierPath() - Smooth curves
  • getStraightPath() - Straight lines
  • getSmoothStepPath() - Orthogonal with rounded corners
  • getSmoothStepPath({ 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:

import { EdgeLabelRenderer, BaseEdge, getBezierPath } from '@xyflow/react';

function ButtonEdge(props: EdgeProps) {
  const [edgePath, labelX, labelY] = getBezierPath(props);
  return (
    \x3C>
      \x3CBaseEdge id={props.id} path={edgePath} />
      \x3CEdgeLabelRenderer>
        \x3Cdiv
          style={{
            position: 'absolute',
            transform: `translate(-50%, -50%) translate(${labelX}px, ${labelY}px)`,
            pointerEvents: 'all',
          }}
          className="nodrag nopan"
        >
          \x3Cbutton onClick={() => console.log('Delete')}>×\x3C/button>
        \x3C/div>
      \x3C/EdgeLabelRenderer>
    \x3C/>
  );
}

See Custom Edges Reference for animated edges, time labels, and SVG text patterns.

Viewport Control

Use useReactFlow() hook for programmatic viewport control:

import { useReactFlow } from '@xyflow/react';

function ViewportControls() {
  const { fitView, zoomIn, zoomOut, setCenter, screenToFlowPosition } = useReactFlow();

  // Fit all nodes in view
  const handleFitView = () => fitView({ padding: 0.2, duration: 400 });

  // Zoom controls
  const handleZoomIn = () => zoomIn({ duration: 300 });
  const handleZoomOut = () => zoomOut({ duration: 300 });

  // Center on specific coordinates
  const handleCenter = () => setCenter(250, 250, { zoom: 1.5, duration: 500 });

  // Convert screen coordinates to flow coordinates
  const addNodeAtClick = (event: React.MouseEvent) => {
    const position = screenToFlowPosition({ x: event.clientX, y: event.clientY });
    // Use position to add node
  };

  return null;
}

See Viewport Reference for save/restore state, controlled viewport, and coordinate transformations.

Events

React Flow provides comprehensive event handling:

Node Events

import { NodeMouseHandler, OnNodeDrag } from '@xyflow/react';

const onNodeClick: NodeMouseHandler = (event, node) => {
  console.log('Node clicked:', node.id);
};

const onNodeDrag: OnNodeDrag = (event, node, nodes) => {
  console.log('Dragging:', node.id);
};

\x3CReactFlow
  onNodeClick={onNodeClick}
  onNodeDrag={onNodeDrag}
  onNodeDragStop={onNodeClick}
/>

Edge and Connection Events

import { EdgeMouseHandler, OnConnect } from '@xyflow/react';

const onEdgeClick: EdgeMouseHandler = (event, edge) => console.log('Edge:', edge.id);
const onConnect: OnConnect = (connection) => console.log('Connected:', connection);

\x3CReactFlow onEdgeClick={onEdgeClick} onConnect={onConnect} />

Selection and Viewport Events

import { useOnSelectionChange, useOnViewportChange } from '@xyflow/react';

useOnSelectionChange({
  onChange: ({ nodes, edges }) => console.log('Selected:', nodes.length, edges.length),
});

useOnViewportChange({
  onChange: (viewport) => console.log('Viewport:', viewport.zoom),
});

See Events Reference for complete event catalog including validation, deletion, and error handling.

Common Patterns

Preventing Drag/Pan

\x3Cinput className="nodrag" />
\x3Cbutton className="nodrag nopan">Click me\x3C/button>

Connection Validation

const isValidConnection = (connection: Connection) => {
  return connection.source !== connection.target; // Prevent self-connections
};

\x3CReactFlow isValidConnection={isValidConnection} />

Adding Nodes on Click

const { screenToFlowPosition, setNodes } = useReactFlow();

const onPaneClick = (event: React.MouseEvent) => {
  const position = screenToFlowPosition({ x: event.clientX, y: event.clientY });
  setNodes(nodes => [...nodes, { id: `node-${Date.now()}`, position, data: { label: 'New' } }]);
};

Updating Node Data

const { updateNodeData } = useReactFlow();
updateNodeData('node-1', { label: 'Updated' });
updateNodeData('node-1', (node) => ({ ...node.data, count: node.data.count + 1 }));

Provider Pattern

Wrap the app with ReactFlowProvider when using useReactFlow() outside the flow:

import { ReactFlow, ReactFlowProvider, useReactFlow } from '@xyflow/react';

function Controls() {
  const { fitView } = useReactFlow(); // Must be inside provider
  return \x3Cbutton onClick={() => fitView()}>Fit View\x3C/button>;
}

function App() {
  return (
    \x3CReactFlowProvider>
      \x3CControls />
      \x3CReactFlow nodes={nodes} edges={edges} />
    \x3C/ReactFlowProvider>
  );
}

Implementation gates

Use these sequenced checks before treating an integration as done (they target common footguns, not style preferences).

  1. 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.
  2. Stable nodeTypes / edgeTypes — Do not pass a fresh object literal every render; define maps outside the component or memoize with useMemo and correct deps. Pass: no remount flicker or “maximum update depth” / runaway updates when only selection or viewport changes.
  3. Provider boundary — Components that call useReactFlow() must be descendants of ReactFlowProvider, 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
Usage Guidance
This is documentation and sample code for a React Flow library and looks coherent. Before installing the suggested package (@xyflow/react) verify the package on the npm/pnpm registry or the project's homepage/GitHub to confirm it's the intended library (ensure maintainer, popularity, and repository match). When installing: pin a specific version, inspect package.json for unexpected postinstall scripts, run an npm audit, and consider installing in a sandbox/dev environment first. If you expected the official 'react-flow' package, double-check the package name to avoid typosquatting.
Capability Analysis
Type: OpenClaw Skill Name: react-flow Version: 1.1.1 The skill bundle provides comprehensive documentation and code examples for the React Flow (@xyflow/react) library. All files (SKILL.md and the reference documents) contain standard technical guidance for building node-based graphs, including custom nodes, edges, and event handling, with no evidence of malicious intent, data exfiltration, or prompt injection.
Capability Assessment
Purpose & Capability
The skill's name/description (React Flow for graph/workflow visualization) matches the provided content: code examples for nodes, edges, hooks, viewport control, and custom components. There are no unrelated environment variables, binaries, or config paths requested.
Instruction Scope
SKILL.md and reference files are documentation and code samples only. Examples use browser-local APIs (localStorage) and console logging, and show event handlers and UI behavior. There are no instructions to read system files, export secrets, call unknown external endpoints, or perform broad contextual data collection.
Install Mechanism
There is no automated install spec (skill is instruction-only). The Quick Start suggests running `pnpm add @xyflow/react`, which is reasonable for a JS library. However, the skill metadata lists unknown source/homepage — you should verify the package name/maintainer on the registry (npm/pnpm) before installing.
Credentials
The skill declares no required environment variables or credentials. The only stateful behavior in examples is using browser localStorage to save viewport state, which is appropriate for a client-side UI library.
Persistence & Privilege
always is false, the skill is user-invocable and does not request permanent platform presence or modify other skills/configs. As an instruction-only skill it cannot autonomously execute installs or change agent settings.
How to Use
  1. Make sure OpenClaw is installed (local or Docker)
  2. Run the install command in chat: /install react-flow
  3. After installation, invoke the skill by name or use /react-flow
  4. Provide required inputs per the skill's parameter spec and get structured output
Version History
v1.1.1
- Documentation updated in SKILL.md. - No changes to code or functionality. - Reference links and code samples were preserved.
v1.1.0
- Added comprehensive documentation for React Flow (@xyflow/react), covering installation, setup, and core concepts. - Introduced clear examples for creating nodes, edges, and handles, including TypeScript usage. - Documented advanced features: custom nodes/edges, interactive labels, and programmatic viewport control. - Included usage patterns for state management, dynamic updates, and React Flow hooks. - Linked detailed references for advanced customization and specific patterns.
Metadata
Slug react-flow
Version 1.1.1
License MIT-0
All-time Installs 1
Active Installs 1
Total Versions 2
Frequently Asked Questions

What is React Flow?

React Flow (@xyflow/react) for workflow visualization with custom nodes and edges. Use when building graph visualizations, creating custom workflow nodes, im... It is an AI Agent Skill for Claude Code / OpenClaw, with 153 downloads so far.

How do I install React Flow?

Run "/install react-flow" in the OpenClaw or Claude Code chat to install it in one step — no extra setup required.

Is React Flow free?

Yes, React Flow is completely free, licensed under MIT-0. You can download, install and use it at no cost.

Which platforms does React Flow support?

React Flow is cross-platform and runs anywhere OpenClaw / Claude Code is available (cross-platform).

Who created React Flow?

It is built and maintained by Kevin Anderson (@anderskev); the current version is v1.1.1.

💬 Comments