useNodesData()

GitHub 上的原始碼

這個 Hook 讓您可以訂閱特定節點的 data 物件的變更。

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

簽名

#參數
#nodeIds
字串 | 字串[]
單個節點 ID 或您想要觀察其 `data` 物件的節點 ID 陣列
#回傳值
#id
字串
#type
字串
#data
any | any[]

Typescript

這個 Hook 接受自定義節點類型的泛型類型參數。請參閱我們 Typescript 指南中的此章節以取得更多資訊。

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