DraftJs:不变违反:使用convertToRaw时,block不是BlockNode

问题描述

在草稿js中使用Invariant Violation: block is not a BlockNode时得到convertToRaw

不幸的是,它在代码沙箱中工作正常,但在本地代码中却无法正常工作,这使我很难调试问题: https://codesandbox.io/s/vibrant-ramanujan-c6h4u?file=/src/App.js:0-1194

在我的本地中引发错误的行是:

const v2 = convertToRaw(v1);

这是完整的代码:

import { useState,useRef } from "react";
import { Editor,createEditorState } from "medium-draft";
import Button from "@material-ui/core/Button";
import { convertToRaw } from "draft-js";

export default function PostEditor() {
  const [editorState,setEditorState] = useState(createEditorState());

  //update medium editor
  const changeEditor = (editorState) => {
    setEditorState(editorState);
  };
  const editorRef = useRef();
  const handleSubmit = async (event) => {
    console.log(editorState.getCurrentContent());
    const v1 = editorRef.current.props.editorState.getCurrentContent();
    const v2 = convertToRaw(v1);
    console.log(v2);
  };
  return (
    <div className="App">
      <h1>Hello CodeSandbox</h1>
      <h2>Start editing to see some magic happen!</h2>

      <Editor
        ref={editorRef}
        editorState={editorState}
        onChange={changeEditor}
      />

      <Button
        variant="contained"
        color="primary"
        size="large"
        onClick={(event) => {
          handleSubmit(event);
        }}
      >
        Submit
      </Button>
    </div>
  );
}

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)