首页 > 解决方案 > _rete.createEditor 不是函数,我的代码哪里有问题?

问题描述

我尝试在我的代码盒中实现 rete.js 可视化编程框架,并在我的 canvas.js 文件中使用以下代码:

import "../../styles.css";
import { createEditor } from "../../rete";

function Canvas() {
  return (
    <div className="App">
      <div
        style={{ width: "100vw", height: "100vh" }}
        ref={ref => ref && createEditor(ref)}/>
    </div>
  );
}

export default Canvas;

浏览器显示以下错误消息:

rete.createEditor is not a function
ref
/src/components/layout/Canvas.js:10:40

   7 |     <div className="App">
   8 |       <div
   9 |         style={{ width: "100vw", height: "100vh" }}
> 10 |         ref={ref => ref && createEditor(ref)}/>
     |                                        ^
  11 |     </div>
  12 |   );
  13 | }

你能在这里找出我的错误吗?

标签: reactjscodesandboxvisual-programmingrete

解决方案


查看有关功能组件中 Ref 的反应文档 https://reactjs.org/docs/refs-and-the-dom.html#refs-and-function-components


推荐阅读