[英]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.
这是我遇到的错误。
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.