React Flow

React Flow | Svelte Flow - Powerful open source libraries for building node...

README

xyflow


The xyflow mono repo


The xyflow repository is the home of four packages:
React Flow v11 reactflow v11 branch

We just moved repositories from the @wbkd org to this one. React Flow v11 will remain on the v11 branch. When we have a stable v12, the package name of React Flow will change fromreactflow to @xyflow/react.

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 the and use the libraries you can see it here:


Installation

  
  1. ``` sh
  2. npm install reactflow
  3. ```

Basic usage

  1. ``` jsx
  2. import { useCallback } from 'react';
  3. import ReactFlow, {
  4.   MiniMap,
  5.   Controls,
  6.   Background,
  7.   useNodesState,
  8.   useEdgesState,
  9.   addEdge,
  10. } from 'reactflow';

  11. import 'reactflow/dist/style.css';

  12. const initialNodes = [
  13.   { id: '1', position: { x: 0, y: 0 }, data: { label: '1' } },
  14.   { id: '2', position: { x: 0, y: 100 }, data: { label: '2' } },
  15. ];

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

  17. function Flow() {
  18.   const [nodes, setNodes, onNodesChange] = useNodesState(initialNodes);
  19.   const [edges, setEdges, onEdgesChange] = useEdgesState(initialEdges);

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

  21.   return (
  22.     <ReactFlow
  23.       nodes={nodes}
  24.       edges={edges}
  25.       onNodesChange={onNodesChange}
  26.       onEdgesChange={onEdgesChange}
  27.       onConnect={onConnect}
  28.     >
  29.       <MiniMap />
  30.       <Controls />
  31.       <Background />
  32.     </ReactFlow>
  33.   );
  34. }

  35. export default Flow;
  36. ```

Installation

  
  1. ```sh
  2. npm install @xyflow/svelte
  3. ```

Basic usage


  1. ```
  2. <script lang="ts">
  3.   import { writable } from 'svelte/store';
  4.   import {
  5.     SvelteFlow,
  6.     Controls,
  7.     Background,
  8.     BackgroundVariant,
  9.     MiniMap,
  10.   } from '@xyflow/svelte';

  11.   import '@xyflow/svelte/dist/style.css'
  12.   
  13.   const nodes = writable([
  14.     {
  15.       id: '1',
  16.       type: 'input',
  17.       data: { label: 'Input Node' },
  18.       position: { x: 0, y: 0 }
  19.     },
  20.     {
  21.       id: '2',
  22.       type: 'custom',
  23.       data: { label: 'Node' },
  24.       position: { x: 0, y: 150 }
  25.     }
  26.   ]);

  27.   const edges = writable([
  28.     {
  29.       id: '1-2',
  30.       type: 'default',
  31.       source: '1',
  32.       target: '2',
  33.       label: 'Edge Text'
  34.     }
  35.   ]);
  36. </script>

  37. <SvelteFlow
  38.   {nodes}
  39.   {edges}
  40.   fitView
  41.   on:nodeclick={(event) => console.log('on node click', event)}
  42. >
  43.   <Controls />
  44.   <Background variant={BackgroundVariant.Dots} />
  45.   <MiniMap />
  46. </SvelteFlow>
  47. ```

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.

License


React Flow and Svelte Flow are MIT licensed.