addEdge()
This util is a convenience function to add a new Edge to an
array of edges. It also performs some validation to make sure you don’t add an
invalid edge or duplicate an existing one.
import { addEdge } from '@xyflow/svelte';
 
let edges = $state.raw([]);
 
const onAddEdge = () => {
  const newEdge = {
    id: '1-2',
    source: '1',
    target: '2',
  };
  edges = addEdge(newEdge, edges.current);
};Signature
Parameters:| Name | Type | Default | 
|---|---|---|
edgeParams | EdgeType | ConnectionEither an   | |
edges | EdgeType[]The array of all current edges.  | 
Notes
- If an edge with the same 
targetandsourcealready exists (and the sametargetHandleandsourceHandleif those are set), then this util won’t add a new edge even if theidproperty is different. 
Last updated on