我正在尝试在我的React项目中添加一个开源编辑器。我使用NPM安装了它。为了快速检查它是否已安装,我只是从 npm网站复制粘贴了代码片段。 代码
import React from 'react';
import 'codemirror/lib/codemirror.css';
import '@toast-ui/editor/dist/toastui-editor.css';
import { Editor } from '@toast-ui/react-editor';
class MyComponent extends React.Component {
editorRef = React.createRef();
handleClick = () => {
this.editorRef.current.getInstance().exec('Bold');
};
render() {
return (
<>
<Editor
previewStyle="vertical"
height="400px"
initialEditType="markdown"
initialValue="hello"
ref={this.editorRef}
/>
<button onClick={this.handleClick}>make bold</button>
</>
);
}
}
错误
版本
"tsutils": "^3.17.1"
"react": "^16.13.1"
"react-dom": "^16.13.1"
"react-scripts": "3.4.1"