Draft-js 所见即所得在 onEditorStateChange 之外更新内容状态

问题描述

有没有办法在 onEditorStateChange 之外为编辑器设置内容状态?例如在 useEffect 钩子中。


  const editorFieldContent = EditorState.createWithContent(
    ContentState.createFromBlockArray(convertFromHTML(field.value))
  );

  const [editorState,setEditorState] = useState(editorFieldContent);

  const onEditorChange = (e) => {
    setFieldValue(field.name,draftToHtml(convertToRaw(editorState.getCurrentContent())));

    setEditorState(e);
  };

  useEffect(() => {
    //is there any function in draft js to set content state outside onEditorChange? something like this
    editorState.setContentState(field.value)
  },[field.value])

  <Editor
    name={field.name}
    editorState={editorState}
    onEditorStateChange={onEditorChange}
  />

解决方法

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

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

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