Reactjs React富文本编辑器-按ENTER键清除状态

Reactjs React富文本编辑器-按ENTER键清除状态,reactjs,rich-text-editor,enter,rte,Reactjs,Rich Text Editor,Enter,Rte,我想在按enter键时清除React富文本编辑器()的状态 我的状态是这样的: state = { value: RichTextEditor.createEmptyValue() } <RichTextEditor handleReturn={this.handleReturn} value={this.state.value} onChange={this.onChange}/> RichTextEditor组件提供了handleReturn道具。

我想在按enter键时清除React富文本编辑器()的状态

我的状态是这样的:

state = {
    value: RichTextEditor.createEmptyValue()
}
<RichTextEditor handleReturn={this.handleReturn} value={this.state.value}
          onChange={this.onChange}/>
RichTextEditor
组件提供了handleReturn道具。因此,我实现了以下
handleReturn
功能:

handleReturn = () => {this.setState(prevState => ({
      ...prevState,
      value: RichTextEditor.createValueFromString("", "html")
    }));
}
当我从RichTextEditor自身外部的按钮触发handleReturn函数时,它工作正常,状态(和文本输入区域)被正确清除。但是,当通过enter键触发相同的HandlerReturn时,它不是在清除状态;但是我可以看到HandlerReturn函数被正确触发。我将函数传递到组件,如下所示:

state = {
    value: RichTextEditor.createEmptyValue()
}
<RichTextEditor handleReturn={this.handleReturn} value={this.state.value}
          onChange={this.onChange}/>

感谢您的帮助。谢谢


更新:我最终直接实现了底层的
draft.js
library()。这是一个非常顺利的过程,它通过绕过
react-rte
解决了这个问题。因此,如果可能的话,我建议您进行切换。

这可能会有所帮助,有点长,只需重置输入,但它可以工作

handleReturn=()=>{
设{editorState}=this.state;
让contentState=editorState.getCurrentContent();
const firstBlock=contentState.getFirstBlock();
const lastBlock=contentState.getLastBlock();
const allSelected=新选择状态({
anchorKey:firstBlock.getKey(),
主持人偏移:0,
focusKey:lastBlock.getKey(),
focusOffset:lastBlock.getLength(),
hasFocus:对
});
contentState=Modifier.removeRange(contentState,allSelected,'backward');
editorState=editorState.push(editorState,contentState,'remove range');
editorState=editorState.forceSelection(contentState,contentState.getSelectionAfter());
this.setState({editorState});