首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在React组件中添加Rete.js可视化编程编辑器

如何在React组件中添加Rete.js可视化编程编辑器
EN

Stack Overflow用户
提问于 2020-05-05 15:17:52
回答 1查看 1.2K关注 0票数 0

我正在尝试将Rete.js包含在react中,我尝试了文档中所说的内容,但得到了以下错误:

代码语言:javascript
复制
TypeError: Cannot read property 'style' of null
new EditorView
src/view/index.ts:25
  22 | this.container = container;
  23 | this.components = components;
  24 | 
> 25 | this.container.style.overflow = 'hidden';

下面是我的代码片段

代码语言:javascript
复制
import React from 'react';

import Rete from "rete";
import ConnectionPlugin from 'rete-connection-plugin';
import ReactRenderPlugin from 'rete-react-render-plugin';


const numSocket = new Rete.Socket('Number value');

class NumComponent extends Rete.Component {
  constructor() {
    super('Number');
  }

  builder(node) {
    let out = new Rete.Output('num', 'Number', numSocket);

    node.addOutput(out);
  }

  worker(node, inputs, outputs) {
    outputs['num'] = node.data.num;
  }
}

const container = document.querySelector('#rete');
const editor = new Rete.NodeEditor('demo@0.1.0', container);

editor.use(ConnectionPlugin)
editor.use(ReactRenderPlugin)

const numComponent = new NumComponent();
editor.register(numComponent);

const engine = new Rete.Engine('demo@0.1.0');
engine.register(numComponent);

editor.on('process nodecreated noderemoved connectioncreated connectionremoved', async () => {
    await engine.abort();
    await engine.process(editor.toJSON());
});


const Dashboard = () => {

  return (
    
    <div id="rete"></div>

  );
};

export default Dashboard;

请帮我解决这个问题,我已经尝试了很长一段时间了。如果有人能帮上忙那就太好了。

EN

回答 1

Stack Overflow用户

发布于 2021-05-28 15:42:42

你这么做太早了,你还没有渲染容器。将构造放入useEffect / componentDidUpdate中。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/61607748

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档