useNodeId()
你可以使用此 hook 来获取其内部使用的节点的 id。如果你需要在渲染树的更深层使用节点的 id,但又不想手动通过 prop 一层层传递 id,则它非常有用。
🌐 You can use this hook to get the id of the node it is used inside. It is useful if you need the node’s id deeper in the render tree but don’t want to manually drill down the id as a prop.
import { useNodeId } from '@xyflow/react';
export default function CustomNode() {
return (
<div>
<span>This node has an id of </span>
<NodeIdDisplay />
</div>
);
}
function NodeIdDisplay() {
const nodeId = useNodeId();
return <span>{nodeId}</span>;
}签名
🌐 Signature
Parameters:This function does not accept any parameters.
Returns:注释
🌐 Notes
- 此钩子应仅在自定义节点或其子节点内使用。
Last updated on