useNode(id)
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:| Name | Type | Default |
|---|---|---|
id | stringThe id of the node to return. |
NodeType | undefinedTypeScript
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);