← 返回 Skills 市场
React Flow Implementation
作者
Kevin Anderson
· GitHub ↗
· v1.1.1
· MIT-0
189
总下载
0
收藏
1
当前安装
2
版本数
在 OpenClaw 中安装
/install 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...
使用说明 (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.”
- Styles on the page — Pass 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. useReactFlowboundary — Pass if every caller ofuseReactFlow()is a descendant of\x3CReactFlowProvider>that wraps the same tree as\x3CReactFlow />(or you have intentionally split stores and can name both roots).- Stable
nodeTypes/edgeTypes— Pass if those maps are module-scope constants oruseMemowith stable deps—not a new{ ... }literal each render in the component that renders\x3CReactFlow />. - Handles match edges — Pass if for nodes with multiple
Handleids, every edge that must land on a specific handle setssourceHandle/targetHandleaccordingly (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.
安全使用建议
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.
功能分析
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.
能力评估
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.
如何使用
- 确保已安装 OpenClaw(本地或 Docker 部署)
- 在对话框中输入安装命令:
/install react-flow-implementation - 安装完成后,直接呼叫该 Skill 的名称或使用
/react-flow-implementation触发 - 根据 Skill 的参数说明提供必要输入,即可获得结构化输出
版本历史
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.
元数据
常见问题
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... 它是一个面向 Claude Code / OpenClaw 的 AI Agent Skill 插件,目前累计下载 189 次。
如何安装 React Flow Implementation?
在 OpenClaw 或 Claude Code 对话框中运行命令「/install react-flow-implementation」即可一键安装,无需额外配置。
React Flow Implementation 是免费的吗?
是的,React Flow Implementation 完全免费,采用 MIT-0 许可证,可自由下载、安装和使用。
React Flow Implementation 支持哪些平台?
React Flow Implementation 跨平台运行,可在任意部署了 OpenClaw / Claude Code 的环境中使用(cross-platform)。
谁开发了 React Flow Implementation?
由 Kevin Anderson(@anderskev)开发并维护,当前版本 v1.1.1。
推荐 Skills