Javascript js草稿中的RichUtils.handleKeyCommand错误:this.props.editorState.isInCompositionMode不是函数错误
我使用的是Draft Js,在尝试使用RichUtils的handleKeyCommand时,应用程序停止,我得到一个错误:“this.props.editorState.isInCompositionMode不是函数错误” 有人能帮忙吗 谢谢Javascript js草稿中的RichUtils.handleKeyCommand错误:this.props.editorState.isInCompositionMode不是函数错误,javascript,reactjs,draftjs,Javascript,Reactjs,Draftjs,我使用的是Draft Js,在尝试使用RichUtils的handleKeyCommand时,应用程序停止,我得到一个错误:“this.props.editorState.isInCompositionMode不是函数错误” 有人能帮忙吗 谢谢 const MyEditor = () => { const [editorState, setEditorState] = useState(()=>EditorState.createEmpty()) const editor
const MyEditor = () => {
const [editorState, setEditorState] = useState(()=>EditorState.createEmpty())
const editor = useRef(null)
useEffect(() => {focus()}, [])
const onChange = (editorState) => setEditorState({ editorState });
const focus = () => editor.current.focus()
const handleKeyCommand = (command, editorState) => {
const newState = RichUtils.handleKeyCommand(editorState, command)
debugger;
if (newState) {
onChange(newState);
return 'handled';
}
return 'not-handled';
}
return (
<div className="editor" onClick={focus}>
<Editor
editorState={editorState}
handleKeyCommand={handleKeyCommand}
onChange={setEditorState}
ref={editor}
placeholder="Tell your story"
spellCheck
/>
</div>
);
}
export default MyEditor
constmyeditor=()=>{
常量[editorState,setEditorState]=useState(()=>editorState.createEmpty())
常量编辑器=useRef(null)
useEffect(()=>{focus()},[]))
const onChange=(editorState)=>setEditorState({editorState});
const focus=()=>editor.current.focus()
const handleKeyCommand=(命令,编辑器状态)=>{
const newState=RichUtils.handleKeyCommand(editorState,command)
调试器;
如果(新闻状态){
onChange(新闻状态);
返回“已处理”;
}
返回“未处理”;
}
返回(
);
}
导出默认MyEditor