简体   繁体   English

未捕获的错误:对象作为 React 子项无效。 使用反应流编辑器时

[英]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.

相关问题 React:Uncaught Error:对象作为React子对象无效 - React: Uncaught Error: Objects are not valid as a React child 未捕获的不变违规:对象无效作为React子代。 如果要渲染子级集合,请改用数组 - Uncaught Invariant Violation: Objects are not valid as a React child. If you meant to render a collection of children, use an array instead 未捕获的错误:对象作为React子对象无效 - Uncaught Error: Objects are not valid as a React child 对象作为 React 子级无效。 如果您打算渲染一组子项,请改用数组 - 错误 Solidity - React - Objects are not valid as a React child. If you meant to render a collection of children, use an array instead - Error Solidity - React 未捕获的错误:对象作为 React 子项无效 - Uncaught error: Objects are not valid as a React child 对象作为 React 子级无效。 找到:带有键 {background, color} 的对象 - Objects are not valid as a React child. found: object with keys {background, color} 错误:对象作为 React 子项无效。 如果您打算渲染一组孩子,请改用数组 - Error: Objects are not valid as a React child. If you meant to render a collection of children, use an array instead 错误:函数作为 React 子项无效。 不确定错误在哪里 - Error: Functions are not valid as a React child. Unsure of where error is ReactJS 错误:对象作为 React 子项无效。 如果您打算渲染一组孩子,请改用数组 - ReactJS Error: Objects are not valid as a React child. If you meant to render a collection of children, use an array instead “对象作为 React 子对象是无效的。 如果您打算渲染一组子项,请改用数组。” 错误 - “Objects are not valid as a React child. If you meant to render a collection of children, use an array instead.” error
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM