React에 통합하기
먼저 설치 및 기본 사용를 읽으십시오. 높이가 명시적으로 설정되는 컨테이너의 Univer Pdfs를 마운트 아래의 React 구성 요소.
통합 단계
useEffect에서 Univer 인스턴스를 만듭니다.useEffect의 정리 함수에서 인스턴스를 해제합니다.
플러그인 설정
UniverUIPlugin
containerstring | HTMLElement편집기를 마운트할 DOM 요소 또는 해당 요소의 ID입니다.
UniverLicensePlugin
licensestring클라이언트 라이선스 파일의 내용입니다.
예제 코드
각 마운트는 자체 아이 컨테이너를 가져옵니다. 예를 들어 주변 React 정리가 완료 된 후 마이크로 태스크에서 분해되므로 React 루트가 React 커밋 중에 비동기적으로 마운트되지 않습니다.
TSX
import { useEffect, useRef } from 'react'import { UniverLicensePlugin } from '@univerjs-pro/license'import { UniverPdfsPlugin } from '@univerjs-pro/pdfs'import { UniverPdfsUIPlugin } from '@univerjs-pro/pdfs-ui'import PdfsUIkoKR from '@univerjs-pro/pdfs-ui/locale/ko-KR'import { LocaleType, mergeLocales, Univer } from '@univerjs/core'import { FUniver } from '@univerjs/core/facade'import DesignkoKR from '@univerjs/design/locale/ko-KR'import { UniverUIPlugin } from '@univerjs/ui'import UIkoKR from '@univerjs/ui/locale/ko-KR'import '@univerjs/design/lib/index.css'import '@univerjs/ui/lib/index.css'import '@univerjs-pro/pdfs-ui/lib/index.css'import '@univerjs-pro/pdfs/facade'export function UniverEditor() { const containerRef = useRef<HTMLDivElement>(null) useEffect(() => { const host = containerRef.current if (!host) return const container = document.createElement('div') container.style.height = '100%' host.append(container) const univer = new Univer({ locale: LocaleType.KO_KR, locales: { [LocaleType.KO_KR]: mergeLocales( DesignkoKR, UIkoKR, PdfsUIkoKR, ), }, }) univer.registerPlugin(UniverLicensePlugin, { license: 'your license.txt', }) univer.registerPlugin(UniverUIPlugin, { container }) univer.registerPlugin(UniverPdfsPlugin) univer.registerPlugin(UniverPdfsUIPlugin) const univerAPI = FUniver.newAPI(univer) univerAPI.createPdf({ name: 'Untitled PDF' }) return () => { queueMicrotask(() => { univer.dispose() container.remove() }) } }, []) return <div ref={containerRef} style={{ height: 600 }} />}이 가이드는 어떠셨나요?