← Back to Skills Marketplace
anderskev

React Flow Implementation

by Kevin Anderson · GitHub ↗ · v1.1.1 · MIT-0
cross-platform ✓ Security Clean
189
Downloads
0
Stars
1
Active Installs
2
Versions
Install in OpenClaw
/install react-flow-implementation
Description
Implements React Flow node-based UIs correctly using @xyflow/react. Use when building flow charts, diagrams, visual editors, or node-based applications with...
README (SKILL.md)

React Flow Implementation

Quick Start

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

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

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

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

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

  return (
    \x3Cdiv style={{ width: '100%', height: '100vh' }}>
      \x3CReactFlow
        nodes={nodes}
        edges={edges}
        onNodesChange={onNodesChange}
        onEdgesChange={onEdgesChange}
        onConnect={onConnect}
        fitView
      />
    \x3C/div>
  );
}

Implementation gates

Run these in order; do not skip ahead on “looks fine.”

  1. Styles on the pagePass if the bundle that renders \x3CReactFlow /> imports @xyflow/react/dist/style.css (or equivalent CSS pipeline) so nodes/edges are visible and hit-targets match visuals.
  2. useReactFlow boundaryPass if every caller of useReactFlow() is a descendant of \x3CReactFlowProvider> that wraps the same tree as \x3CReactFlow /> (or you have intentionally split stores and can name both roots).
  3. Stable nodeTypes / edgeTypesPass if those maps are module-scope constants or useMemo with stable deps—not a new { ... } literal each render in the component that renders \x3CReactFlow />.
  4. Handles match edgesPass if for nodes with multiple Handle ids, every edge that must land on a specific handle sets sourceHandle / targetHandle accordingly (or you accept default handle resolution deliberately).

See ADDITIONAL_COMPONENTS.md for MiniMap, Controls, Background, NodeToolbar, and NodeResizer patterns.

Core Patterns

TypeScript Types

import type { Node, Edge, NodeProps, BuiltInNode } from '@xyflow/react';

// Define custom node type with data shape
type CustomNode = Node\x3C{ value: number; label: string }, 'custom'>;

// Combine with built-in nodes
type MyNode = CustomNode | BuiltInNode;
type MyEdge = Edge\x3C{ weight?: number }>;

// Use throughout app
const [nodes, setNodes] = useNodesState\x3CMyNode>(initialNodes);

Custom Nodes

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

// Define node type
type CounterNode = Node\x3C{ count: number }, 'counter'>;

// Always wrap in memo for performance
const CounterNode = memo(function CounterNode({ data, isConnectable }: NodeProps\x3CCounterNode>) {
  return (
    \x3C>
      \x3CHandle type="target" position={Position.Top} isConnectable={isConnectable} />
      \x3Cdiv className="counter-node">
        Count: {data.count}
        {/* nodrag prevents dragging when interacting with button */}
        \x3Cbutton className="nodrag" onClick={() => console.log('clicked')}>
          Increment
        \x3C/button>
      \x3C/div>
      \x3CHandle type="source" position={Position.Bottom} isConnectable={isConnectable} />
    \x3C/>
  );
});

// Register in nodeTypes (define OUTSIDE component to avoid re-renders)
const nodeTypes = { counter: CounterNode };

// Use in ReactFlow
\x3CReactFlow nodeTypes={nodeTypes} ... />

Multiple Handles

// Use handle IDs when a node has multiple handles of same type
\x3CHandle type="source" position={Position.Right} id="a" />
\x3CHandle type="source" position={Position.Right} id="b" style={{ top: 20 }} />

// Connect with specific handles
const edge = {
  id: 'e1-2',
  source: '1',
  sourceHandle: 'a',
  target: '2',
  targetHandle: null
};

Custom Edges

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

function CustomEdge({ id, sourceX, sourceY, targetX, targetY, sourcePosition, targetPosition, data }: EdgeProps) {
  const [edgePath, labelX, labelY] = getSmoothStepPath({
    sourceX, sourceY, sourcePosition,
    targetX, targetY, targetPosition,
  });

  return (
    \x3C>
      \x3CBaseEdge id={id} path={edgePath} />
      \x3Ctext x={labelX} y={labelY} className="edge-label">{data?.label}\x3C/text>
    \x3C/>
  );
}

const edgeTypes = { custom: CustomEdge };

State Management

Controlled (Recommended for Production)

// External state with change handlers
const [nodes, setNodes] = useState\x3CNode[]>(initialNodes);
const [edges, setEdges] = useState\x3CEdge[]>(initialEdges);

const onNodesChange = useCallback(
  (changes) => setNodes((nds) => applyNodeChanges(changes, nds)),
  []
);

const onEdgesChange = useCallback(
  (changes) => setEdges((eds) => applyEdgeChanges(changes, eds)),
  []
);

\x3CReactFlow
  nodes={nodes}
  edges={edges}
  onNodesChange={onNodesChange}
  onEdgesChange={onEdgesChange}
/>

Using useReactFlow

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

function FlowControls() {
  const {
    getNodes, setNodes, addNodes, updateNodeData,
    getEdges, setEdges, addEdges,
    fitView, zoomIn, zoomOut, setViewport,
    deleteElements, toObject,
  } = useReactFlow();

  const addNode = () => {
    addNodes({ id: `${Date.now()}`, position: { x: 100, y: 100 }, data: { label: 'New' } });
  };

  return \x3Cbutton onClick={addNode}>Add Node\x3C/button>;
}

// Must wrap in provider when using useReactFlow
function App() {
  return (
    \x3CReactFlowProvider>
      \x3CFlow />
      \x3CFlowControls />
    \x3C/ReactFlowProvider>
  );
}

Updating Node Data

const { updateNodeData } = useReactFlow();

// Merge with existing data
updateNodeData(nodeId, { label: 'Updated' });

// Replace data entirely
updateNodeData(nodeId, { newField: 'value' }, { replace: true });

Viewport & Fit View

// Fit on initial render
\x3CReactFlow fitView fitViewOptions={{ padding: 0.2, maxZoom: 1 }} />

// Programmatic control
const { fitView, setViewport, getViewport, zoomTo } = useReactFlow();

// Fit to specific nodes
fitView({ nodes: [{ id: '1' }, { id: '2' }], duration: 500 });

// Set exact viewport
setViewport({ x: 100, y: 100, zoom: 1.5 }, { duration: 300 });

Connection Validation

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

  // Custom validation logic
  const sourceNode = getNode(connection.source);
  const targetNode = getNode(connection.target);

  return sourceNode?.type !== targetNode?.type;
}, []);

\x3CReactFlow isValidConnection={isValidConnection} />

Common Props Reference

\x3CReactFlow
  // Core data
  nodes={nodes}
  edges={edges}
  onNodesChange={onNodesChange}
  onEdgesChange={onEdgesChange}

  // Custom types (define OUTSIDE component)
  nodeTypes={nodeTypes}
  edgeTypes={edgeTypes}

  // Connections
  onConnect={onConnect}
  connectionMode={ConnectionMode.Loose}  // Allow target-to-target
  isValidConnection={isValidConnection}

  // Viewport
  fitView
  minZoom={0.1}
  maxZoom={4}
  defaultViewport={{ x: 0, y: 0, zoom: 1 }}

  // Interaction
  nodesDraggable={true}
  nodesConnectable={true}
  elementsSelectable={true}
  panOnDrag={true}
  zoomOnScroll={true}

  // Additional components
  \x3CMiniMap />
  \x3CControls />
  \x3CBackground variant={BackgroundVariant.Dots} />
\x3C/ReactFlow>

CSS Classes for Interaction

Class Effect
nodrag Prevent dragging when clicking element
nowheel Prevent zoom on wheel events
nopan Prevent panning from element
nokey Prevent keyboard events (use on inputs)

Additional Components

See ADDITIONAL_COMPONENTS.md for MiniMap, Controls, Background, NodeToolbar, NodeResizer.

Usage Guidance
This skill is essentially documentation and example code—safe to read. Before copying code into a project, verify the npm package name (@xyflow/react) and its source (registry/repository) to ensure it’s the intended library (typosquatting is possible). If you install the package in your application, review that package's repository, version, and license, and prefer installing from the official registry (npm/Yarn) rather than arbitrary URLs. Note the examples assume you will implement saving/restoring state yourself; there are no hidden network calls or secret access in the skill content.
Capability Analysis
Type: OpenClaw Skill Name: react-flow-implementation Version: 1.1.1 The skill bundle provides legitimate documentation and code snippets for implementing React Flow using the @xyflow/react library. It includes standard implementation patterns, TypeScript types, and best practices for custom nodes and edges across SKILL.md, ADDITIONAL_COMPONENTS.md, and EDGE_PATHS.md. No indicators of malicious intent, data exfiltration, or prompt injection were found.
Capability Assessment
Purpose & Capability
The name and description (React Flow implementation guidance) match the SKILL.md content: code samples, component patterns, and edge/node utilities for @xyflow/react. The skill does not request unrelated credentials, binaries, or config paths.
Instruction Scope
SKILL.md is limited to code examples, usage guidance, and implementation gates for React components. It does not instruct the agent to read system files, access environment variables, call external endpoints, or exfiltrate data.
Install Mechanism
No install spec is provided (instruction-only). Nothing is downloaded or written to disk by the skill itself, which minimizes installation risk. The examples assume you will add @xyflow/react as a dependency in your project.
Credentials
The skill declares no environment variables, credentials, or config paths and its examples do not reference secret data. This is proportionate for a documentation/example skill.
Persistence & Privilege
The skill is not always-enabled and does not request persistent system privileges or modify other skills/configuration. Autonomous invocation is allowed (platform default) but is not combined with other risky privileges.
How to Use
  1. Make sure OpenClaw is installed (local or Docker)
  2. Run the install command in chat: /install react-flow-implementation
  3. After installation, invoke the skill by name or use /react-flow-implementation
  4. Provide required inputs per the skill's parameter spec and get structured output
Version History
v1.1.1
- Added an "Implementation gates" checklist section detailing critical integration checks for React Flow usage in React apps. - The checklist covers requirements for CSS imports, `useReactFlow` provider boundaries, stable custom type maps, and handle/edge matching. - Linked additional usage patterns for advanced components via the [ADDITIONAL_COMPONENTS.md] reference. - No breaking changes to code samples or existing documentation structure.
v1.1.0
react-flow-implementation 1.1.0 – Improved docs and usage guidance - Added comprehensive usage instructions for building node-based UIs with @xyflow/react. - Examples now cover custom nodes, edges, multiple handles, and TypeScript type safety. - State management patterns clarified (controlled vs. hook-based). - Guidance for viewport control, connection validation, and React Flow props. - Included concise CSS and integration tips for robust real-world implementations.
Metadata
Slug react-flow-implementation
Version 1.1.1
License MIT-0
All-time Installs 1
Active Installs 1
Total Versions 2
Frequently Asked Questions

What is React Flow Implementation?

Implements React Flow node-based UIs correctly using @xyflow/react. Use when building flow charts, diagrams, visual editors, or node-based applications with... It is an AI Agent Skill for Claude Code / OpenClaw, with 189 downloads so far.

How do I install React Flow Implementation?

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

Is React Flow Implementation free?

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

Which platforms does React Flow Implementation support?

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

Who created React Flow Implementation?

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

💬 Comments