-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTipTap.tsx
34 lines (29 loc) · 884 Bytes
/
TipTap.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import { FC, useEffect } from 'react';
import { useEditor, EditorContent } from '@tiptap/react';
import StarterKit from '@tiptap/starter-kit';
interface TipTapProps {
content: string;
handleUpdate: (value: string) => void;
}
const Tiptap: FC<TipTapProps> = ({ content = '', handleUpdate }) => {
const editor = useEditor({
extensions: [StarterKit],
editorProps: {
attributes: {
class: 'prose prose-sm sm:prose lg:prose-lg xl:prose-2xl m-5 focus:outline-none',
},
},
content: content.toString(),
onUpdate: ({ editor }) => {
handleUpdate(editor.getText());
},
});
useEffect(() => {
if (!editor || !editor.commands || !editor.getText) return;
if (editor.getText() !== content) {
editor.commands.setContent(content);
}
}, [content]);
return <EditorContent editor={editor} />;
};
export default Tiptap;