Reactjs DraftJS编辑器返回不正确的状态-但可以使用RichUtils更改状态
我对draftjs有意见 编辑器返回的是我假设的编辑器状态的旧版本 当我在渲染期间跟踪状态时,在按下按钮后,编辑器状态包含粗体标志-但是在编辑器组件中键入后,返回的状态对象不包含这些标志 我不知所措,我试着从repo中的示例中完美地复制代码Reactjs DraftJS编辑器返回不正确的状态-但可以使用RichUtils更改状态,reactjs,typescript,draftjs,Reactjs,Typescript,Draftjs,我对draftjs有意见 编辑器返回的是我假设的编辑器状态的旧版本 当我在渲染期间跟踪状态时,在按下按钮后,编辑器状态包含粗体标志-但是在编辑器组件中键入后,返回的状态对象不包含这些标志 我不知所措,我试着从repo中的示例中完美地复制代码 public render(): JSX.Element { const { main, identifier } = this.props; const section = getSection(main, identifier); const
public render(): JSX.Element {
const { main, identifier } = this.props;
const section = getSection(main, identifier);
const editorState = section.config.editorState; // from redux store
return (
<>
<button
onClick={() => {
const s = RichUtils.toggleInlineStyle(editorState, 'BOLD');
this.updateSectionEditorState(s);
}}
>
GO BOLD
</button>
<Editor
editorState={editorState}
onChange={this.updateSectionEditorState}
/>
</>
);
}
updateSectionEditorState = (e: EditorState) => {
const { main, updateSection, identifier } = this.props;
const section = getSection(main, identifier);
const newSection: DropComponent = {
...section,
config: {
...section.config,
editorState: e,
},
};
updateSection(newSection); // dispatchs action to update state
};
public render():JSX.Element{
const{main,identifier}=this.props;
const section=getSection(main,标识符);
const editorState=section.config.editorState;//来自redux存储
返回(
{
const s=RichUtils.toggleInlineStyle(editorState,'BOLD');
此.updateSectionEditor状态;
}}
>
大胆
);
}
updateSectionEditorState=(e:EditorState)=>{
const{main,updateSection,identifier}=this.props;
const section=getSection(main,标识符);
const newSection:DropComponent={
…第节,
配置:{
…section.config,
编辑状态:e,
},
};
updateSection(newSection);//将操作分派到更新状态
};
有趣,你能做一个工作的jsfiddle
?