简体   繁体   English

代码镜像将无法在我的React应用程序中运行

[英]Code Mirror will not function in my React application

I am attempting to create a Web IDE sort of like Eclipse Orion. 我正在尝试创建类似Eclipse Orion的Web IDE。 The code editor that I plan to use is Code Mirror; 我计划使用的代码编辑器是Code Mirror; the only difficulty is that I cannot get the code editor to load. 唯一的困难是我无法加载代码编辑器。 Here is the error that I am encountering. 这是我遇到的错误。

devtools的屏幕截图

Here is the code that got me to this issue. 这是让我解决此问题的代码。

import React, { Component } from 'react';
import codemirror from 'codemirror';

import 'codemirror/mode/markdown/markdown';
import 'codemirror/lib/codemirror.css';
import 'codemirror/theme/monokai.css';

class Editor extends Component {
  componentDidMount = () => {
    this.codeMirror = codemirror.fromTextArea(this.codeEditor, {
      mode: 'markdown'
    });
  };
  codeEditor = React.createRef();
  render = () => (
    <div>
      <textarea ref={this.codeEditor} />
    </div>
  );
}

export default Editor;

This issue has been stated many times here, but with no solution that made sense in my situation. 这个问题在这里已经被陈述过很多次了,但是在我的情况下,没有任何有意义的解决方案。 Thanks in advance. 提前致谢。

This code seemed to do the trick, it was just an issue with the ref . 这段代码似乎可以解决问题,这只是ref的问题。

import React, { Component } from 'react';
import codemirror from 'codemirror';

import 'codemirror/mode/markdown/markdown';
import 'codemirror/lib/codemirror.css';

class Editor extends Component {
  componentDidMount = () => {
    this.codeMirror = codemirror(this.editor, {
      mode: 'markdown'
    });
  };
  ref = React.createRef();
  render = () => (
    <div>
      <div ref={self => this.editor = self} />
    </div>
  );
}

export default Editor;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在我的 React 聊天应用程序中发送代码片段 - Sending code snippets in my react chat application 如何从反应js中的代码镜像中获取值? - How to get a value from code mirror in react js? 如何为反应代码镜像添加右括号和右标签 - How to add close bracket and close tag for react code mirror 将React应用程序中的Javascript分配给功能组件中的{},进行代码审查 - Javascript, in a React application assign to {} in a function component, code review (反应,Redux)将调度代码放在onChange函数中时发生错误 - (React, Redux) Error occurs when I put my dispatch code in my onChange function :/slug 在我的反应应用程序中不起作用 - :/slug is not working in my react application 我的应用程序中有多个React副本 - Multiple copies of React in my Application "<i>Why does changing state (useState) break my p5.js code?<\/i>为什么更改状态 (useState) 会破坏我的 p5.js 代码?<\/b> <i>(React + p5.js application)<\/i> (反应 + p5.js 应用程序)<\/b>" - Why does changing state (useState) break my p5.js code? (React + p5.js application) 在应用程序启动时调用函数以进行响应 - Call a function on application startup in react 类型错误:.map 不是函数 - React 应用程序 - TypeError: .map is not a function - React application
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM