refactoring
This commit is contained in:
@@ -10,7 +10,10 @@ function isClassComponent(Component: any) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function isForwardRefComponent(Component: any) {
|
function isForwardRefComponent(Component: any) {
|
||||||
return !!(typeof Component === 'object' && Component.$$typeof?.toString() === 'Symbol(react.forward_ref)')
|
return !!(
|
||||||
|
typeof Component === 'object'
|
||||||
|
&& Component.$$typeof?.toString() === 'Symbol(react.forward_ref)'
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface ReactRendererOptions {
|
export interface ReactRendererOptions {
|
||||||
@@ -19,10 +22,10 @@ export interface ReactRendererOptions {
|
|||||||
as?: string,
|
as?: string,
|
||||||
}
|
}
|
||||||
|
|
||||||
type ComponentType = React.Component | React.FunctionComponent | React.ForwardRefExoticComponent<{
|
type ComponentType =
|
||||||
items: any[];
|
| React.Component
|
||||||
command: any;
|
| React.FunctionComponent
|
||||||
} & React.RefAttributes<unknown>>
|
| React.ForwardRefExoticComponent<{ items: any[], command: any } & React.RefAttributes<unknown>>
|
||||||
|
|
||||||
export class ReactRenderer {
|
export class ReactRenderer {
|
||||||
id: string
|
id: string
|
||||||
@@ -53,7 +56,7 @@ export class ReactRenderer {
|
|||||||
const Component = this.component
|
const Component = this.component
|
||||||
const props = this.props
|
const props = this.props
|
||||||
|
|
||||||
if (isClassComponent(Component) || isForwardRefComponent(Component)) {
|
if (isClassComponent(Component) || isForwardRefComponent(Component)) {
|
||||||
props.ref = (ref: React.Component) => {
|
props.ref = (ref: React.Component) => {
|
||||||
this.ref = ref
|
this.ref = ref
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user