useEdges
Source on GitHub (opens in a new tab)
This hook returns an array of the current edges. Components that use this hook will re-render whenever any edge changes.
import { useEdges } from '@xyflow/react';
export default function () {
const edges = useEdges();
return <div>There are currently {edges.length} edges!</div>;
}
Signature
Name | Type |
---|---|
#Returns |
|
Edge<T>[] An array of all edges currently in the flow. |
Typescript
This hook accepts a generic type argument of custom edge types. See this section in our Typescript guide for more information.
const nodes = useEdges<CustomEdgeType>();
Notes
- Relying on
useEdges
unecessarily can be a common cause of performance issues. Whenever any edge changes, this hook will cause the component to re-render. Often we actually care about something more specific, like when the number of edges changes: where possible try to useuseStore
instead.