Javascript Draft.js编辑器组件isn';不可编辑
试图学习如何在我自己的应用程序中使用DraftJS React组件,我遇到了一个大问题。我遵循了这个例子 我使用了Javascript Draft.js编辑器组件isn';不可编辑,javascript,reactjs,draftjs,Javascript,Reactjs,Draftjs,试图学习如何在我自己的应用程序中使用DraftJS React组件,我遇到了一个大问题。我遵循了这个例子 我使用了createreact-app来获取基本样板文件,并且导入了编辑器和状态对象,并像示例一样实现 import React, { Component } from 'react'; import {Editor, EditorState} from 'draft-js'; class App extends Component { constructor(props){
createreact-app
来获取基本样板文件,并且导入了编辑器和状态对象,并像示例一样实现
import React, { Component } from 'react';
import {Editor, EditorState} from 'draft-js';
class App extends Component {
constructor(props){
super(props);
this.state = {editorState: EditorState.createEmpty()};
this.onChange = (editorState) => this.setState({editorState});
}
render() {
return (
<div className='container'>
<h2> Welcome to the editor</h2>
<Editor
editorState={this.state.editorState}
onChange={this.onChange}
placeholder='Make Something Great.' />
</div>
);
}
}
export default App;
import React,{Component}来自'React';
从“草稿js”导入{Editor,EditorState};
类应用程序扩展组件{
建造师(道具){
超级(道具);
this.state={editorState:editorState.createEmpty()};
this.onChange=(editorState)=>this.setState({editorState});
}
render(){
返回(
欢迎来到编辑
);
}
}
导出默认应用程序;
这个问题是,它显示的是H1和带有占位符文本的编辑器,但它不允许我更改编辑器的内容
我很确定我错过了什么。我需要做什么才能启用编辑
更新:事实证明它是可编辑的,我只需单击占位符下面的。奇怪但还好。发生这种情况是因为Draft.css不包括在内 最后一个组件应如下所示:
import React, { Component } from 'react';
import {Editor, EditorState} from 'draft-js';
import 'draft-js/dist/Draft.css';
class App extends Component {
constructor(props){
super(props);
this.state = {editorState: EditorState.createEmpty()};
this.onChange = (editorState) => this.setState({editorState});
}
render() {
return (
<div className='container'>
<h2> Welcome to the editor</h2>
<Editor
editorState={this.state.editorState}
onChange={this.onChange}
placeholder='Make Something Great.' />
</div>
);
}
}
export default App;
import React,{Component}来自'React';
从“草稿js”导入{Editor,EditorState};
导入'draft js/dist/draft.css';
类应用程序扩展组件{
建造师(道具){
超级(道具);
this.state={editorState:editorState.createEmpty()};
this.onChange=(editorState)=>this.setState({editorState});
}
render(){
返回(
欢迎来到编辑
);
}
}
导出默认应用程序;