useInternalNodes()
This hook returns an array of internal node objects for the passed node IDs. Components that use this hook will re-render whenever any of the selected nodes change.
import { useInternalNodes } from '@xyflow/react';
export default function () {
const internalNodes = useInternalNodes(['node-1', 'node-2']);
const absolutePosition = internalNodes[0].internals.positionAbsolute;
return (
<div>
The absolute position of node-1 is at:
<p>x: {absolutePosition.x}</p>
<p>y: {absolutePosition.y}</p>
</div>
);
}Signature
Parameters:| Name | Type | Default |
|---|---|---|
ids | readonly string[]An array of node IDs to observe. An empty array returns no nodes. |
TypeScript
This hook accepts a generic type argument of custom node types. See this section in our TypeScript guide for more information.
const internalNodes = useInternalNodes<CustomNodeType>(['node-1', 'node-2']);