File tree Expand file tree Collapse file tree 2 files changed +15
-1
lines changed Expand file tree Collapse file tree 2 files changed +15
-1
lines changed Original file line number Diff line number Diff line change @@ -62,7 +62,9 @@ export function supportRef(nodeOrComponent: any): boolean {
62
62
return true ;
63
63
}
64
64
65
- export function supportNodeRef ( node : React . ReactNode ) : boolean {
65
+ export function supportNodeRef < T = any > (
66
+ node : React . ReactNode ,
67
+ ) : node is React . ReactElement & React . RefAttributes < T > {
66
68
if ( ! isValidElement ( node ) ) {
67
69
return false ;
68
70
}
Original file line number Diff line number Diff line change @@ -186,5 +186,17 @@ describe('ref', () => {
186
186
expect ( supportNodeRef ( < FC /> ) ) . toBeFalsy ( ) ;
187
187
expect ( supportNodeRef ( < RefFC /> ) ) . toBeTruthy ( ) ;
188
188
} ) ;
189
+
190
+ it ( 'ref' , ( ) => {
191
+ const FC : React . FC = ( ) => < div /> ;
192
+ const RefFC = React . forwardRef <
193
+ HTMLDivElement ,
194
+ React . HTMLAttributes < HTMLDivElement >
195
+ > ( ( props , ref ) => < div { ...props } ref = { ref } /> ) ;
196
+ const com = < FC /> ;
197
+ const refCom = < RefFC ref = { React . createRef ( ) } /> ;
198
+ expect ( supportNodeRef ( com ) && com . ref ) . toBeFalsy ( ) ;
199
+ expect ( supportNodeRef ( refCom ) && refCom . ref ) . toBeTruthy ( ) ;
200
+ } ) ;
189
201
} ) ;
190
202
} ) ;
You can’t perform that action at this time.
0 commit comments