提交 0a74a978 authored 作者: 王鹏飞's avatar 王鹏飞

refactor(admin): extract editor availability lifecycle

上级 71f8d7d5
...@@ -41,6 +41,7 @@ import PreviewModal from "../features/preview/PreviewDialog"; ...@@ -41,6 +41,7 @@ import PreviewModal from "../features/preview/PreviewDialog";
import HistoryModal from "../features/history/HistoryDialog"; import HistoryModal from "../features/history/HistoryDialog";
import { EditorHeader } from './EditorHeader' import { EditorHeader } from './EditorHeader'
import { EditorSidebar } from './EditorSidebar' import { EditorSidebar } from './EditorSidebar'
import { useEditorLifecycle } from './useEditorLifecycle'
import "../index.less"; import "../index.less";
...@@ -512,15 +513,7 @@ const WangEditorCustomer = (props, ref) => { ...@@ -512,15 +513,7 @@ const WangEditorCustomer = (props, ref) => {
}; };
}, [editor]); }, [editor]);
useEffect(() => { useEditorLifecycle({ editor, gData, disabled });
if (editor) {
if (gData.length > 0 && !disabled) {
editor.enable();
} else {
editor.disable();
}
}
}, [gData, editor, disabled]);
const tabKeyChange = (key) => { const tabKeyChange = (key) => {
if (key === "text") { if (key === "text") {
......
import { useEffect } from 'react'
export const useEditorLifecycle = ({ editor, gData, disabled }) => {
useEffect(() => {
if (!editor) return
if (gData.length > 0 && !disabled) editor.enable()
else editor.disable()
}, [editor, gData, disabled])
}
Markdown 格式
0% 或
您添加了 0 人 到此讨论。请谨慎行事。
请先完成此评论的编辑!
请 注册 或者 后发表评论