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日,部分内容可能存在时效性,请注意甄别。

相关推荐

更多教程
ThinkPHP6模板中多次字符串替换使用方法 前端技术 ThinkPHP6模板中多次字符串替换使用方法

  简介:场景在tp6开发过程...

31 浏览
react-flow自定义放大、缩小、居中工具栏 前端技术 react-flow自定义放大、缩小、居中工具栏

前言 最近在使用react-flow过程...

28 浏览
2022最新常用React 组件库大全 前端技术 2022最新常用React 组件库大全

项目地址 https://github....

130 浏览

评论