From 8651474a00395402a0f35bb4cbea6715f5a97efa Mon Sep 17 00:00:00 2001 From: manzhenhua Date: Thu, 14 May 2020 11:13:43 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=AD=90=E7=BB=84=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/braftEditor/index.tsx | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/components/braftEditor/index.tsx b/components/braftEditor/index.tsx index c58627d..9fe8aea 100644 --- a/components/braftEditor/index.tsx +++ b/components/braftEditor/index.tsx @@ -38,13 +38,14 @@ const EditorDemo: React.FC = ({ value, language = 'zh', onChange, cRef, const [editorState, setEditorState] = useState(BraftEditor.createEditorState(null)); const [percent, setPercent] = useState(0); // 进度条 const previewRef = useRef(null); - useEffect(() => { - // 使用BraftEditor.createEditorState将html字符串转换为编辑器需要的editorStat - setEditorState(BraftEditor.createEditorState(value)); + if (value && typeof value === 'object') { // 不做转换 + setEditorState(value) + } else { + // 使用BraftEditor.createEditorState将html字符串转换为编辑器需要的editorStat + setEditorState(BraftEditor.createEditorState(value)); + } }, [value]); - - // 获取HTML const getHtml = () => { // 直接调用editorState.toHTML()来获取HTML格式的内容 @@ -57,8 +58,7 @@ const EditorDemo: React.FC = ({ value, language = 'zh', onChange, cRef, const handleEditorChange = (editorState: any) => { setEditorState(editorState); if (onChange) { - const htmlContent = editorState.toHTML(); - onChange(editorState, htmlContent); + onChange(editorState); } }; -- 2.21.0