destroy

3.1.0 버전부터 지원, 2.19.0 버전부터 지원합니다.

에디터에서 사용된 리소스를 정리합니다 — 메모리 누수를 방지하기 위해 이벤트 리스너와 참조를 제거합니다.

페이지가 언로드될 때(onBeforeUnload) 자동으로 호출됩니다. 싱글 페이지 애플리케이션(SPA)에서는 컴포넌트가 더 이상 사용되지 않을 때(일반적으로 언마운트 또는 라우트 변경 시) 이 함수를 호출합니다.

예시

// React example — call destroy on unmount
useEffect(() => {
  editorInstance = new SynapEditor();

  // when leaving the page or unmounting, call destroy
  return () => {
    if (editorInstance) {
      editorInstance.destroy();
      editorInstance = null;
    }
  };
}, []);