useEdges()
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
Parameters:This function does not accept any parameters.
Returns: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
unnecessarily 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.
Last updated on