Skip to Content
React Flow 13 is here! Read the announcement →
ReferenceHooks

useEdge(id)

Source on GitHub 

This hook returns the current edge with the specified ID. Components that use this hook will re-render whenever the edge changes, including when it is selected or moved.

import { useEdge } from '@xyflow/react'; export default function ({ id }) { const edge = useEdge(id); return <div>The current edge ID is {edge?.id}</div>; }

Signature

Parameters:
NameTypeDefault
idstring

The id of the edge to return.

Returns:
EdgeType | undefined

TypeScript

This hook accepts a generic type argument of custom edge types. See this section in our TypeScript guide for more information.

const edge = useEdge<CustomEdgeType>(id);