mirror of
https://github.com/ueberdosis/tiptap.git
synced 2024-11-24 03:39:01 +08:00
fix(react): the editor passed into EditorContent can be null
This commit is contained in:
parent
6d1621c513
commit
d4d99e8ad3
5
.changeset/gentle-ads-poke.md
Normal file
5
.changeset/gentle-ads-poke.md
Normal file
@ -0,0 +1,5 @@
|
||||
---
|
||||
"@tiptap/react": patch
|
||||
---
|
||||
|
||||
When changing the types, a bug was introduced where null could no longer be a valid value
|
@ -3,7 +3,7 @@ import { ReactPortal } from 'react'
|
||||
|
||||
import { ReactRenderer } from './ReactRenderer.js'
|
||||
|
||||
export type EditorWithContentComponent = Editor & { contentComponent: ContentComponent | null }
|
||||
export type EditorWithContentComponent = Editor & { contentComponent?: ContentComponent | null }
|
||||
export type ContentComponent = {
|
||||
setRenderer(id: string, renderer: ReactRenderer): void;
|
||||
removeRenderer(id: string): void;
|
||||
|
@ -108,7 +108,7 @@ export class PureEditorContent extends React.Component<
|
||||
this.initialized = false
|
||||
|
||||
this.state = {
|
||||
hasContentComponentInitialized: Boolean((props.editor as EditorWithContentComponent).contentComponent),
|
||||
hasContentComponentInitialized: Boolean((props.editor as EditorWithContentComponent | null)?.contentComponent),
|
||||
}
|
||||
}
|
||||
|
||||
@ -121,7 +121,7 @@ export class PureEditorContent extends React.Component<
|
||||
}
|
||||
|
||||
init() {
|
||||
const editor = this.props.editor as EditorWithContentComponent
|
||||
const editor = this.props.editor as EditorWithContentComponent | null
|
||||
|
||||
if (editor && !editor.isDestroyed && editor.options.element) {
|
||||
if (editor.contentComponent) {
|
||||
@ -165,7 +165,7 @@ export class PureEditorContent extends React.Component<
|
||||
}
|
||||
|
||||
componentWillUnmount() {
|
||||
const editor = this.props.editor as EditorWithContentComponent
|
||||
const editor = this.props.editor as EditorWithContentComponent | null
|
||||
|
||||
if (!editor) {
|
||||
return
|
||||
|
Loading…
Reference in New Issue
Block a user