refactoring

This commit is contained in:
Philipp Kühn
2021-03-08 23:10:10 +01:00
parent 7f698a7553
commit d64ddf6c1b
5 changed files with 217 additions and 211 deletions

View File

@@ -0,0 +1,48 @@
import React from 'react'
import { Editor } from './Editor'
type EditorContentProps = {
editor: Editor | null
}
export class PureEditorContent extends React.Component<EditorContentProps, EditorContentProps> {
editorContentRef: React.RefObject<any>
constructor(props: EditorContentProps) {
super(props)
this.editorContentRef = React.createRef()
this.state = {
editor: this.props.editor
}
}
componentDidUpdate() {
const { editor } = this.props
if (editor && editor.options.element) {
const element = this.editorContentRef.current
element.appendChild(editor.options.element.firstChild)
editor.setOptions({
element,
})
editor.contentComponent = this
// TODO: why setTimeout?
setTimeout(() => {
editor.createNodeViews()
}, 0)
}
}
render() {
return (
<div ref={this.editorContentRef} />
)
}
}
export const EditorContent = React.memo(PureEditorContent);