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 { SvelteFlow, addEdge } from '@xyflow/svelte';
export default function Flow() {
const [nodes, setNodes, onNodesChange] = useNodesState([]);
const [edges, setEdges, onEdgesChange] = useEdgesState([]);
const onConnect = useCallback(
(connection) => {
setEdges((oldEdges) => addEdge(connection, oldEdges));
},
[setEdges],
);
return <SvelteFlow nodes={nodes} edges={edges} onConnect={onConnect} />;
}Signature
| Name | Type |
|---|---|
#Params | |
# edge | |
# edges | Edge[] |
#Returns | |
Edge[] |
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