react-flow报错:Couldn’t create edge for source handle id: “undefined”

前言 最近在使用react-flow中,控制台报错:Couldn’t create edge fo […]

前言

最近在使用react-flow中,控制台报错:Couldn’t create edge for source handle id: “undefined”,刚开始查看时找不到原因,于是上官方git下,大概说的时Handle组件的问题。

代码分析

下面代码是我自定义node的代码,其中有个问题是: 我是动态判断去渲染上下两个连接点的。所以我直接让 firstOrLast === true 后,发现渲染没有问题。

{firstOrLast === 0 ? "" : <Handle type="target" position={Position.Top} />}
<NodeWrapper
	onDoubleClick={onNodeDbClicked}
	style={{
		width: width ?? 200 + "px",
		height: height ?? 32 + "px"
	}}>
	{getNodeIcon(type, resStatus, pduStatus, pduSid)}
	<NodeInfoWrapper>{`${title ?? "名称获取失败"}  `}</NodeInfoWrapper>
</NodeWrapper>
{firstOrLast === 2 ? "" : <Handle type="source" position={Position.Bottom} />}

 

解决问题

将中间节点的: firstOrLast 值设置为1,将最后一排的设置为2,第一排的设置为0,如此问题解决。

nodeClone.push({
	id: softInst.sid,
	type: "textUpdater",
	data: {
		sid: softInst.sid,
		title: software.name,
		firstOrLast: 1
	},
	position: { x: 0, y: 80 }
});

edgeClone.push({
	id: makeUuid(softInst.sid, computer.sid),
	source: computer.sid,
	target: softInst.sid
	// animated: true,
	// style: { stroke: "red" }
});

 最终效果

最后正常渲染

 

版权声明
文章标题:react-flow报错:Couldn’t create edge for source handle id: “undefined”
文章链接:https://blog.chiyuba.com/qianduanjishu/528.html
声明:本站所有文章,如无特殊说明或标注,均为本站原创发布,转载或引用请注明出处。
温馨提示:本文最后更新于 2025年7月12日,部分内容可能存在时效性,请注意甄别。

相关推荐

更多教程
react-flow自定义节点 前端技术 react-flow自定义节点

前言 在开发react-flow的过程中...

2 浏览
ssycms模板开发之模板详情模板页 UI相关 ssycms模板开发之模板详情模板页

以下列出常用详情模板页面调用标签代码 你...

5 浏览
git将分支合并到主分支 前端技术 git将分支合并到主分支

  简介:方法 1:使用 gi...

4 浏览

评论