useNodesData()
此 Hook 允许您订阅特定节点 data 对象的更改。
import { useNodesData } from '@xyflow/react';
export default function () {
const nodeData = useNodesData('nodeId-1');
const nodesData = useNodesData(['nodeId-1', 'nodeId-2']);
}签名
| 名称 | 类型 |
|---|---|
#参数 | |
# nodeIds | string | string[]单个节点 ID 或您想要观察其 `data` 对象的节点 ID 数组 |
#返回值 | |
# id | string |
# type | string |
# data | any | any[] |
TypeScript
此 Hook 接受自定义节点类型的泛型类型参数。有关更多信息,请参阅我们的 TypeScript 指南中的 本节。
const nodesData = useNodesData<NodesType>(['nodeId-1', 'nodeId-2']);