2024-08-14
New edge examples

Hayleigh Thompson
Software Engineer
Here’s a care drop of new edge examples including how to animate nodes along an edge path, how to create temporary edges, and a demo of every connection event. We hope this new bundle of examples will help you level up your flow game!
import {
ReactFlow,
useNodesState,
useEdgesState,
Background,
} from '@xyflow/react';
import { AnimatedNodeEdge } from './AnimatedNodeEdge';
import './index.css';
const initialNodes = [
{ id: '1', position: { x: -100, y: -200 }, data: { label: 'A' } },
{ id: '2', position: { x: 100, y: 200 }, data: { label: 'B' } },
{ id: '3', position: { x: 0, y: 0 }, data: { label: 'C' } },
];
const edgeTypes = {
animatedNode: AnimatedNodeEdge,
};
const initialEdges = [
{
id: '1->2',
type: 'animatedNode',
source: '1',
target: '2',
data: { node: '3' },
},
];
const EdgesFlow = () => {
const [nodes, , onNodesChange] = useNodesState(initialNodes);
const [edges, , onEdgesChange] = useEdgesState(initialEdges);
return (
<ReactFlow
nodes={nodes}
edges={edges}
edgeTypes={edgeTypes}
onNodesChange={onNodesChange}
onEdgesChange={onEdgesChange}
fitView
>
<Background />
</ReactFlow>
);
};
export default EdgesFlow;This is a breakdown of what’s been added:
-
Two examples in one showing how to animate SVG elements and other nodes along an edge path.
-
A new example showing how to create a temporary edge attached to only one handle. These edges can be picked back up and connected at a later time.
-
We have a lot of events related to connections so we’ve created a small demo showing every connection and event and when they are triggered.
