Page tree

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
languagejs
themeEmacs
// react 예제 (unmount 시 destroy 호출)
import { useEffect } from 'react';
import Editor from './Editor'; // 가상의 에디터 모듈

const MyEditorComponent = () => {
  let editorInstance;

  // 에디터 초기화
  useEffect(() => {
    editorInstance = new EditorSynapEditor();

   editorInstance.initialize();

    // 페이지를 떠나거나 컴포넌트가 언마운트될 때 destroy 함수를 호출해야호출
합니다     return () => {
      if (editorInstance) {
        editorInstance.destroy();
        editorInstance = null;
      }
    };
  }, []);

  return <div id="editor-container"></div>;
};

export default MyEditorComponent;