From 8c960c64e28d3639654b9f506c66516cf4ef8fc7 Mon Sep 17 00:00:00 2001 From: 0xGingi <0xgingi@0xgingi.com> Date: Fri, 15 Nov 2024 14:45:04 +0000 Subject: [PATCH] webapp: fix richtext not loading note until swapping to another mode --- src/components/RichTextEditor.tsx | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/components/RichTextEditor.tsx b/src/components/RichTextEditor.tsx index 4d267a5..0fac697 100644 --- a/src/components/RichTextEditor.tsx +++ b/src/components/RichTextEditor.tsx @@ -19,6 +19,7 @@ import { IconH3, IconClearFormatting, } from '@tabler/icons-react'; +import { useEffect } from 'react'; interface RichTextEditorProps { content: string; @@ -40,7 +41,18 @@ export function RichTextEditor({ content, onChange }: RichTextEditorProps) { onUpdate: ({ editor }: { editor: Editor }) => { onChange(editor.getHTML()); }, + editorProps: { + attributes: { + class: 'rich-text-editor', + }, + }, }); + + useEffect(() => { + if (editor && content !== editor.getHTML()) { + editor.commands.setContent(content); + } + }, [editor, content]); if (!editor) { return null;