// components/simple-editor.js import React, { useRef, useState, useCallback } from "react"; import { Editor } from "@tinymce/tinymce-react"; function SimpleEditor(props) { const editorRef = useRef(null); const [editorInstance, setEditorInstance] = useState(null); const handleInit = useCallback((evt, editor) => { editorRef.current = editor; setEditorInstance(editor); // Set initial content if (props.initialData) { editor.setContent(props.initialData); } // Disable automatic content updates editor.settings.auto_focus = false; editor.settings.forced_root_block = 'p'; // Store the onChange callback editor.onChangeCallback = props.onChange; // Handle content changes without triggering re-renders editor.on('change keyup input', (e) => { if (editor.onChangeCallback) { const content = editor.getContent(); editor.onChangeCallback(content); } }); }, [props.initialData, props.onChange]); return ( ); } export default SimpleEditor;