參考Hooks

useConnection

GitHub 上的原始碼

useConnection Hook 會在有作用中的連線互動時傳回目前的連線狀態。如果沒有作用中的連線互動,則每個屬性都會傳回 null。這個 Hook 的典型用例是根據特定條件(例如,連線是否有效)來著色控制點。

import { useConnection } from '@xyflow/react';
 
export default function () {
  const connection = useConnection();
 
  return (
    {connection &&
      <div>
        Someone is trying to make a connection from {connection.fromNode} to this one.
      </div>
    }
    {!connection &&
      <div>
        There are currently no incoming connections!
      </div>
    }
    )
}

簽名

#參數
#selector?
(connection: ConnectionState<InternalNode<NodeType>>) => T
一個可選的選擇器函式,用於提取 ConnectionState 資料的切片。使用選擇器可以防止元件在您不關心的資料可能會變更時重新渲染。如果未提供選擇器,則會傳回整個 ConnectionState 物件而不變更。
#傳回
T