mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2025-05-14 15:14:56 -04:00
Feature/lazy load components (#590)
This commit is contained in:
parent
9c38655a92
commit
101292da92
46 changed files with 261 additions and 248 deletions
|
@ -1,19 +1,21 @@
|
|||
import React, { useEffect, useRef } from 'react'
|
||||
import { renderAbc } from 'abcjs'
|
||||
|
||||
export interface AbcFrameProps {
|
||||
code: string
|
||||
}
|
||||
|
||||
export const AbcFrame: React.FC<AbcFrameProps> = ({ code }) => {
|
||||
const container = useRef<HTMLDivElement>(null)
|
||||
|
||||
useEffect(() => {
|
||||
if (container.current) {
|
||||
renderAbc(container.current, code)
|
||||
if (!container.current) {
|
||||
return
|
||||
}
|
||||
const actualContainer = container.current
|
||||
import(/* webpackChunkName: "abc.js" */ 'abcjs').then((imp) => {
|
||||
imp.renderAbc(actualContainer, code)
|
||||
}).catch(() => { console.error('error while loading abcjs') })
|
||||
}, [code])
|
||||
|
||||
return (
|
||||
<div ref={container} className={'bg-white text-center'}/>
|
||||
)
|
||||
return <div ref={container} className={'bg-white text-center'}/>
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue