[英]Uncaught Error: Objects are not valid as a React child. when using react-flow-editor
I followed this tutorial to make a react-flow-editor component:我按照本教程制作了一个 react-flow-editor 组件:
https://www.npmjs.com/package/react-flow-editor https://www.npmjs.com/package/react-flow-editor
Then I adapted it for my project as the above one uses typescript.然后我为我的项目调整了它,因为上面使用了 typescript。 Below is my code:
下面是我的代码:
import { Config, Editor, Node } from 'react-flow-editor';
import React, { Component } from 'react';
class Workflow extends Component {
constructor(props) {
super(props);
this.state = {
nodes: [
{
id: 'Node 1',
name: 'First Node',
payload: { h1: 'hello' },
inputs: [{
connection: [], name: 'input 1'
}],
outputs: []
}],
config: {
resolver: function(payload) {
if ( payload.type === '') return <h2 />;
return (
<p>{payload}</p>
);
},
connectionType: 'bezier',
grid: true,
demoMode: true,
}
};
}
render() {
return (
<div>
<Editor config={this.state.config} nodes={this.state.nodes} />
</div>
);
}
}
export default Workflow;
When running it, I get the following error:运行它时,我收到以下错误:
Uncaught Error: Objects are not valid as a React child (found: object with keys {id, name, payload, inputs, outputs}). If you meant to render a collection of children, use an array instead.
What am I doing wrong?我究竟做错了什么?
Sorry for the late answer.抱歉回复晚了。 The issue is that you try to render a complex object directly with react.
问题是您尝试使用 react 直接渲染复杂的 object。
Try this fix:试试这个修复:
- <p>{payload}</p>
+ <p>{payload.payload.h1}</p>
This should solve the issue.这应该可以解决问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.