chore(react/type_widget): refactor event handling slightly

This commit is contained in:
Elian Doran 2025-09-22 12:43:43 +03:00
parent f6631b7b9a
commit 8a185262fb
No known key found for this signature in database

View File

@ -31,10 +31,6 @@ export default function CKEditorWithWatchdog({ content, className, tabIndex, isC
isClassicEditor: !!isClassicEditor
});
if (onNotificationWarning) {
editor.plugins.get("Notification").on("show:warning", onNotificationWarning);
}
setEditor(editor);
return editor;
@ -52,6 +48,14 @@ export default function CKEditorWithWatchdog({ content, className, tabIndex, isC
// React to content changes.
useEffect(() => editor?.setData(content ?? ""), [ editor, content ]);
// React to notification warning callback.
useEffect(() => {
if (!onNotificationWarning || !editor) return;
const notificationPlugin = editor.plugins.get("Notification");
notificationPlugin.on("show:warning", onNotificationWarning);
return () => notificationPlugin.off("show:warning", onNotificationWarning);
}, [ editor, onNotificationWarning ]);
// React to on change listener.
useEffect(() => {
if (!editor) return;
@ -60,9 +64,7 @@ export default function CKEditorWithWatchdog({ content, className, tabIndex, isC
}, [ editor, onChange ]);
return (
<div ref={containerRef} className={className} tabIndex={tabIndex}>
</div>
<div ref={containerRef} className={className} tabIndex={tabIndex} />
);
}