import React, { useRef, useEffect } from "react"; import { Editor } from "@tinymce/tinymce-react"; function StableEditor(props) { const editorRef = useRef(null); const onChangeRef = useRef(props.onChange); // Update onChange ref when props change useEffect(() => { onChangeRef.current = props.onChange; }, [props.onChange]); const handleInit = (evt, editor) => { editorRef.current = editor; // Set initial content if provided if (props.initialData) { editor.setContent(props.initialData); } // Use a simple change handler that doesn't trigger re-renders editor.on('change', () => { if (onChangeRef.current) { onChangeRef.current(editor.getContent()); } }); }; return ( ); } export default StableEditor;