Page tree

Versions Compared

Key

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

e

Table of Contents

...


Info
title참고

프로젝트마다 폴더 구조가 다를 수 있으므로, 가이드를 참고하여 프로젝트에 맞도록 적절히 적용해주세요.

...

Code Block
languagejs
themeEmacs
titleSynapEditorComponent.js
import { useEffect } from 'react';
import license from '../scripts/synapeditor/license.json';
import SynapEditor from '../scripts/synapeditor/synapeditor.min';
import '../scripts/synapeditor/synapeditor.min.css';

function SynapEditorComponent({ editorId }) {
    useEffect(() => {
        const config = {
            'editor.license': license // 라이센스를 설정합니다.
			// 기타 설정을 추가합니다. 필요에 따라 prop을 통해 값을 받아서 설정할 수 있도록 처리합니다.
        };
        const html = ''; // 에디터 초기화시 표시할 html을 설정합니다. 필요에 따라 prop을 통해 값을 받아서 설정할 수 있도록 처리합니다.
        const eventListener = {
            initialized: (event) => {
				// 에디터가 초기화 되었을 때 실행되는 이벤트 리스너입니다. 
				// 에디터가 초기화 되면 수행되어야 하는 작업을 작성합니다.
                console.log('에디터 초기화 완료: ', event);
            }
        };

        editorInstance = new SynapEditor(editorId, config, html, eventListener);

		// 릴리즈 3.1.0 이상
		// 페이지를 떠나거나 컴포넌트가 언마운트될 때 destroy 함수를 호출 에디터에서 사용한 리소르를 정리하는 함수로 이벤트와 참조를 제거해 메모리 누수를 방지합니다.
		return () => {
			if(editorInstance) {
				editorInstance.destroy();
        		editorInstance = null;
			}
		}
    }, [editorId]);

    return (
        <div id={editorId}></div>
    );
}

export default SynapEditorComponent;

...