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

useNode(id)

Source on GitHub 

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

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

Signature

Parameters:
NameTypeDefault
idstring

The id of the node to return.

Returns:
NodeType | undefined

TypeScript

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

const node = useNode<CustomNodeType>(id);