Skip to Content
参考钩子

useNodesData()

GitHub上的源代码 

这个钩子允许你订阅特定节点 data 对象的变化。

🌐 This hook lets you subscribe to changes of a specific nodes data object.

import { useNodesData } from '@xyflow/react'; export default function () { const nodeData = useNodesData('nodeId-1'); const nodesData = useNodesData(['nodeId-1', 'nodeId-2']); }

签名

🌐 Signature

Parameters:
NameTypeDefault
nodeIdstring

The id of the node to get the data from.

Returns:
Pick<NodeType, "id" | "type" | "data"> | null

An object (or array of object) with id, type, data representing each node.

TypeScript

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

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

const nodesData = useNodesData<NodesType>(['nodeId-1', 'nodeId-2']);
Last updated on