Skip to content

Commit

Permalink
fix: Improve ReactRenderer types (#2011)
Browse files Browse the repository at this point in the history
  • Loading branch information
rfgamaral authored Oct 11, 2021
1 parent 503a3f2 commit 31d8ab3
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions packages/react/src/ReactRenderer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ export interface ReactRendererOptions {
as?: string,
}

type ComponentType =
type ComponentType<R> =
| React.ComponentClass
| React.FunctionComponent
| React.ForwardRefExoticComponent<{ items: any[], command: any } & React.RefAttributes<unknown>>
| React.ForwardRefExoticComponent<{ items: any[], command: any } & React.RefAttributes<R>>

export class ReactRenderer {
export class ReactRenderer<R = unknown> {
id: string

editor: ExtendedEditor
Expand All @@ -41,9 +41,9 @@ export class ReactRenderer {

reactElement: React.ReactNode

ref: React.Component | null = null
ref: R | null = null

constructor(component: ComponentType, { editor, props = {}, as = 'div' }: ReactRendererOptions) {
constructor(component: ComponentType<R>, { editor, props = {}, as = 'div' }: ReactRendererOptions) {
this.id = Math.floor(Math.random() * 0xFFFFFFFF).toString()
this.component = component
this.editor = editor as ExtendedEditor
Expand All @@ -58,7 +58,7 @@ export class ReactRenderer {
const props = this.props

if (isClassComponent(Component) || isForwardRefComponent(Component)) {
props.ref = (ref: React.Component) => {
props.ref = (ref: R) => {
this.ref = ref
}
}
Expand Down

0 comments on commit 31d8ab3

Please sign in to comment.