xyflow
React Flow | Svelte Flow - Powerful open source libraries for building node-based UIs with React (https://reactflow.dev) or Svelte (https://svelteflow.dev). Ready out-of-the-box and infinitely customizable.
Top Related Projects
React Flow | Svelte Flow - Powerful open source libraries for building node-based UIs with React (https://reactflow.dev) or Svelte (https://svelteflow.dev). Ready out-of-the-box and infinitely customizable.
🚀 JavaScript diagramming library that uses SVG and HTML for rendering.
a super simple, no-nonsense diagramming library written in react that just works
Directed graph layout for JavaScript
Graph theory (network) library for visualisation and analysis
mxGraph is a fully client side JavaScript diagramming library
Quick Overview
XYflow is a powerful and flexible library for building node-based editors, flow diagrams, and interactive graphs in React applications. It provides a set of customizable components and hooks that allow developers to create complex, interactive visualizations with ease.
Pros
- Highly customizable and extensible
- Excellent performance, even with large graphs
- Rich set of features including zoom, pan, and minimap
- Active community and regular updates
Cons
- Steep learning curve for complex implementations
- Limited built-in node types (though custom nodes can be created)
- Documentation can be overwhelming for beginners
- Some advanced features require additional setup
Code Examples
Creating a basic flow:
import ReactFlow from 'reactflow';
const elements = [
{ id: '1', type: 'input', data: { label: 'Input Node' }, position: { x: 250, y: 25 } },
{ id: '2', data: { label: 'Default Node' }, position: { x: 100, y: 125 } },
{ id: '3', type: 'output', data: { label: 'Output Node' }, position: { x: 250, y: 250 } },
{ id: 'e1-2', source: '1', target: '2' },
{ id: 'e2-3', source: '2', target: '3' },
];
function Flow() {
return <ReactFlow elements={elements} />;
}
Adding custom node types:
import ReactFlow, { Handle } from 'reactflow';
const CustomNode = ({ data }) => (
<div style={{ background: '#f0f0f0', padding: 10 }}>
<Handle type="target" position="left" />
<div>{data.label}</div>
<Handle type="source" position="right" />
</div>
);
const nodeTypes = {
custom: CustomNode,
};
function Flow() {
return <ReactFlow elements={elements} nodeTypes={nodeTypes} />;
}
Using hooks for interactivity:
import ReactFlow, { useNodes, useEdges, addEdge } from 'reactflow';
function Flow() {
const [nodes, setNodes, onNodesChange] = useNodes(initialNodes);
const [edges, setEdges, onEdgesChange] = useEdges(initialEdges);
const onConnect = useCallback((params) => setEdges((eds) => addEdge(params, eds)), [setEdges]);
return (
<ReactFlow
nodes={nodes}
edges={edges}
onNodesChange={onNodesChange}
onEdgesChange={onEdgesChange}
onConnect={onConnect}
/>
);
}
Getting Started
To start using XYflow in your React project:
-
Install the package:
npm install reactflow
-
Import and use in your component:
import ReactFlow from 'reactflow'; import 'reactflow/dist/style.css'; function Flow() { const elements = [ { id: '1', data: { label: 'Node 1' }, position: { x: 250, y: 5 } }, { id: '2', data: { label: 'Node 2' }, position: { x: 100, y: 100 } }, { id: 'e1-2', source: '1', target: '2' }, ]; return <ReactFlow elements={elements} />; } export default Flow;
This will create a simple flow diagram with two connected nodes.
Competitor Comparisons
React Flow | Svelte Flow - Powerful open source libraries for building node-based UIs with React (https://reactflow.dev) or Svelte (https://svelteflow.dev). Ready out-of-the-box and infinitely customizable.
Pros of xyflow
- More comprehensive documentation and examples
- Larger community and more active development
- Better integration with popular frameworks like React
Cons of xyflow
- Steeper learning curve for beginners
- Potentially more complex setup for simple use cases
- Larger bundle size due to additional features
Code Comparison
xyflow:
import ReactFlow from 'reactflow';
const elements = [
{ id: '1', data: { label: 'Node 1' }, position: { x: 250, y: 5 } },
{ id: '2', data: { label: 'Node 2' }, position: { x: 100, y: 100 } },
{ id: 'e1-2', source: '1', target: '2', animated: true },
];
function Flow() {
return <ReactFlow elements={elements} />;
}
xyflow:
import { Graph } from 'xyflow';
const graph = new Graph();
const node1 = graph.addNode({ id: '1', label: 'Node 1', x: 250, y: 5 });
const node2 = graph.addNode({ id: '2', label: 'Node 2', x: 100, y: 100 });
graph.addEdge({ source: node1, target: node2, animated: true });
function Flow() {
return <Graph graph={graph} />;
}
Note: The code comparison is hypothetical as xyflow and xyflow are the same repository. The example demonstrates potential differences in API design and usage between different flow libraries.
🚀 JavaScript diagramming library that uses SVG and HTML for rendering.
Pros of X6
- More comprehensive documentation and examples
- Wider range of built-in graph elements and layouts
- Better performance for large-scale graphs
Cons of X6
- Steeper learning curve due to more complex API
- Less flexible for custom node and edge designs
- Heavier bundle size
Code Comparison
X6:
import { Graph } from '@antv/x6';
const graph = new Graph({
container: document.getElementById('container'),
width: 800,
height: 600,
});
graph.addNode({ x: 100, y: 100, width: 80, height: 40, label: 'Hello' });
xyflow:
import ReactFlow from 'reactflow';
const elements = [
{ id: '1', type: 'input', data: { label: 'Hello' }, position: { x: 100, y: 100 } },
];
function Flow() {
return <ReactFlow elements={elements} />;
}
X6 uses a more imperative approach, while xyflow leverages React's declarative style. X6 offers more fine-grained control over graph elements, but xyflow's React integration makes it easier to work with for developers familiar with React ecosystems.
a super simple, no-nonsense diagramming library written in react that just works
Pros of react-diagrams
- More mature project with a longer history and established community
- Offers a wider range of built-in node and link types
- Provides more customization options for advanced use cases
Cons of react-diagrams
- Steeper learning curve due to more complex API
- Less frequent updates and maintenance compared to xyflow
- Performance can be slower with large diagrams
Code Comparison
react-diagrams:
import createEngine, { DiagramModel, DefaultNodeModel } from '@projectstorm/react-diagrams';
const engine = createEngine();
const model = new DiagramModel();
const node1 = new DefaultNodeModel('Node 1', 'rgb(0,192,255)');
node1.setPosition(100, 100);
model.addAll(node1);
xyflow:
import ReactFlow, { Node, Edge } from 'reactflow';
const nodes: Node[] = [{ id: '1', position: { x: 100, y: 100 }, data: { label: 'Node 1' } }];
const edges: Edge[] = [];
return <ReactFlow nodes={nodes} edges={edges} />;
Both libraries offer powerful diagramming capabilities, but xyflow provides a more modern and streamlined API, making it easier for beginners to get started. react-diagrams offers more advanced features and customization options, which can be beneficial for complex projects but may require more time to master.
Directed graph layout for JavaScript
Pros of dagre
- Specialized in directed graph layout algorithms
- Lightweight and focused on graph rendering
- Well-established with a long history of development
Cons of dagre
- Less active development and maintenance
- Limited to graph visualization, not a full-featured flow diagram tool
- Requires integration with other libraries for interactive features
Code Comparison
dagre:
var g = new dagre.graphlib.Graph();
g.setNode("A", { label: "Node A" });
g.setNode("B", { label: "Node B" });
g.setEdge("A", "B");
dagre.layout(g);
xyflow:
const nodes = [
{ id: '1', position: { x: 0, y: 0 }, data: { label: 'Node 1' } },
{ id: '2', position: { x: 100, y: 100 }, data: { label: 'Node 2' } },
];
const edges = [{ id: 'e1-2', source: '1', target: '2' }];
<ReactFlow nodes={nodes} edges={edges} />
Summary
Dagre is a specialized library for graph layout algorithms, making it ideal for projects focused on graph visualization. It's lightweight and has a long development history. However, it has less active maintenance and limited features compared to xyflow, which offers a more comprehensive solution for interactive flow diagrams with React integration.
Graph theory (network) library for visualisation and analysis
Pros of Cytoscape.js
- More mature and established library with a larger community
- Extensive documentation and examples
- Supports a wider range of graph types and layouts
Cons of Cytoscape.js
- Steeper learning curve due to more complex API
- Heavier library size, which may impact performance for large graphs
- Less focus on modern React integration compared to xyflow
Code Comparison
Cytoscape.js:
cytoscape({
container: document.getElementById('cy'),
elements: [
{ data: { id: 'a' } },
{ data: { id: 'b' } },
{ data: { id: 'ab', source: 'a', target: 'b' } }
],
style: [ /* ... */ ],
layout: { name: 'grid' }
});
xyflow:
import ReactFlow from 'reactflow';
const elements = [
{ id: '1', type: 'input', data: { label: 'Node 1' }, position: { x: 250, y: 5 } },
{ id: '2', data: { label: 'Node 2' }, position: { x: 100, y: 100 } },
{ id: 'e1-2', source: '1', target: '2', animated: true },
];
<ReactFlow elements={elements} />
Both libraries offer powerful graph visualization capabilities, but xyflow provides a more React-centric approach with easier integration for React applications, while Cytoscape.js offers a broader range of features and graph types at the cost of a steeper learning curve.
mxGraph is a fully client side JavaScript diagramming library
Pros of mxgraph
- More mature and feature-rich library with extensive documentation
- Supports a wider range of diagram types and use cases
- Offers both client-side and server-side rendering options
Cons of mxgraph
- Steeper learning curve due to its complexity and extensive API
- Larger file size and potentially heavier performance impact
- Less modern development experience compared to React-based libraries
Code Comparison
mxgraph:
var graph = new mxGraph(container);
var parent = graph.getDefaultParent();
graph.getModel().beginUpdate();
try {
var v1 = graph.insertVertex(parent, null, 'Hello,', 20, 20, 80, 30);
var v2 = graph.insertVertex(parent, null, 'World!', 200, 150, 80, 30);
var e1 = graph.insertEdge(parent, null, '', v1, v2);
} finally {
graph.getModel().endUpdate();
}
xyflow:
import ReactFlow from 'react-flow-renderer';
const elements = [
{ id: '1', data: { label: 'Hello,' }, position: { x: 20, y: 20 } },
{ id: '2', data: { label: 'World!' }, position: { x: 200, y: 150 } },
{ id: 'e1-2', source: '1', target: '2', animated: true },
];
function Flow() {
return <ReactFlow elements={elements} />;
}
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual CopilotREADME
Powerful open source libraries for building node-based UIs with React or Svelte. Ready out-of-the-box and infinitely customizable.
React Flow · Svelte Flow · React Flow Pro · Discord
The xyflow mono repo
The xyflow repository is the home of four packages:
- React Flow 12
@xyflow/react
packages/react - React Flow 11
reactflow
v11 branch - Svelte Flow
@xyflow/svelte
packages/svelte - Shared helper library
@xyflow/system
packages/system
Commercial usage
Are you using React Flow or Svelte Flow for a personal project? Great! No sponsorship needed, you can support us by reporting any bugs you find, sending us screenshots of your projects, and starring us on Github ð
Are you using React Flow or Svelte Flow at your organization and making money from it? Awesome! We rely on your support to keep our libraries developed and maintained under an MIT License, just how we like it. For React Flow you can do that on the React Flow Pro website and for both of our libraries you can do it through Github Sponsors.
Getting started
The best way to get started is to check out the React Flow or Svelte Flow learn section. However if you want to get a sneak peek of how to install and use the libraries you can see it here:
React Flow basic usage
Installation
npm install @xyflow/react
Basic usage
import { useCallback } from 'react';
import {
ReactFlow,
MiniMap,
Controls,
Background,
useNodesState,
useEdgesState,
addEdge,
} from '@xyflow/react';
import '@xyflow/react/dist/style.css';
const initialNodes = [
{ id: '1', position: { x: 0, y: 0 }, data: { label: '1' } },
{ id: '2', position: { x: 0, y: 100 }, data: { label: '2' } },
];
const initialEdges = [{ id: 'e1-2', source: '1', target: '2' }];
function Flow() {
const [nodes, setNodes, onNodesChange] = useNodesState(initialNodes);
const [edges, setEdges, onEdgesChange] = useEdgesState(initialEdges);
const onConnect = useCallback((params) => setEdges((eds) => addEdge(params, eds)), [setEdges]);
return (
<ReactFlow
nodes={nodes}
edges={edges}
onNodesChange={onNodesChange}
onEdgesChange={onEdgesChange}
onConnect={onConnect}
>
<MiniMap />
<Controls />
<Background />
</ReactFlow>
);
}
export default Flow;
Svelte Flow basic usage
Installation
npm install @xyflow/svelte
Basic usage
<script lang="ts">
import { writable } from 'svelte/store';
import {
SvelteFlow,
Controls,
Background,
BackgroundVariant,
MiniMap,
} from '@xyflow/svelte';
import '@xyflow/svelte/dist/style.css'
const nodes = writable([
{
id: '1',
type: 'input',
data: { label: 'Input Node' },
position: { x: 0, y: 0 }
},
{
id: '2',
type: 'custom',
data: { label: 'Node' },
position: { x: 0, y: 150 }
}
]);
const edges = writable([
{
id: '1-2',
type: 'default',
source: '1',
target: '2',
label: 'Edge Text'
}
]);
</script>
<SvelteFlow
{nodes}
{edges}
fitView
on:nodeclick={(event) => console.log('on node click', event)}
>
<Controls />
<Background variant={BackgroundVariant.Dots} />
<MiniMap />
</SvelteFlow>
Releases
For releasing packages we are using changesets in combination with the changeset Github action. The rough idea is:
- create PRs for new features, updates and fixes (with a changeset if relevant for changelog)
- merge into main
- changset creates a PR that bumps all packages based on the changesets
- merge changeset PR if you want to release to Github and npm
The xyflow team
React Flow and Svelte Flow are maintained by the team behind xyflow. If you need help or want to talk to us about a collaboration, reach out through our contact form or by joining our Discord Server.
- Christopher â¢Â Twitter â¢Â Github
- Hayleigh â¢Â Twitter â¢Â Github
- John â¢Â Website â¢Â Mastodon
- Moritz â¢Â Twitter â¢Â Github
- Peter â¢Â Github
License
React Flow and Svelte Flow are MIT licensed.
Top Related Projects
React Flow | Svelte Flow - Powerful open source libraries for building node-based UIs with React (https://reactflow.dev) or Svelte (https://svelteflow.dev). Ready out-of-the-box and infinitely customizable.
🚀 JavaScript diagramming library that uses SVG and HTML for rendering.
a super simple, no-nonsense diagramming library written in react that just works
Directed graph layout for JavaScript
Graph theory (network) library for visualisation and analysis
mxGraph is a fully client side JavaScript diagramming library
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual Copilot