Skip to Content
参考钩子

useInternalNode()

GitHub上的源代码 

此钩子返回特定节点的内部表示。使用此钩子的组件将在任何节点发生变化时重新渲染,包括节点被选中或移动时。

🌐 This hook returns the internal representation of a specific node. Components that use this hook will re-render whenever any node changes, including when a node is selected or moved.

import { useInternalNode } from '@xyflow/react'; export default function () { const internalNode = useInternalNode('node-1'); const absolutePosition = internalNode.internals.positionAbsolute; return ( <div> The absolute position of the node is at: <p>x: {absolutePosition.x}</p> <p>y: {absolutePosition.y}</p> </div> ); }

签名

🌐 Signature

Parameters:
NameTypeDefault
idstring

The ID of a node you want to observe.

Returns:
InternalNode<NodeType> | undefined

The InternalNode object for the node with the given ID.

TypeScript

这个钩子接受自定义节点类型的泛型类型参数。有关更多信息,请参见我们 TypeScript 指南中的这一部分

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

const internalNode = useInternalNode<CustomNodeType>();
Last updated on