Skip to Content
参考钩子

useEdges()

GitHub上的源代码 

这个钩子返回当前边缘的数组。使用这个钩子的组件每当任何边缘发生变化时都会重新渲染。

🌐 This hook returns an array of the current edges. Components that use this hook will re-render whenever any edge changes.

import { useEdges } from '@xyflow/react'; export default function () { const edges = useEdges(); return <div>There are currently {edges.length} edges!</div>; }

签名

🌐 Signature

Parameters:

This function does not accept any parameters.

Returns:
EdgeType[]

An array of all edges currently in the flow.

TypeScript

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

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

const nodes = useEdges<CustomEdgeType>();

注释

🌐 Notes

  • 不必要地依赖 useEdges 通常可能是性能问题的一个常见原因。每当任何边发生变化时,这个 hook 都会导致组件重新渲染。实际上我们通常更关心一些更具体的内容,比如当边的数量发生变化时:尽可能尝试改用 useStore
Last updated on