Skip to content

Commit 60c3785

Browse files
authored
fix: supportRef function for preact (#477)
1 parent 550721c commit 60c3785

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

src/ref.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/* eslint-disable no-param-reassign */
22
import type * as React from 'react';
33
import { isValidElement, ReactNode } from 'react';
4-
import { isFragment, isMemo } from 'react-is';
4+
import { ForwardRef, isFragment, isMemo } from 'react-is';
55
import useMemo from './hooks/useMemo';
66

77
export function fillRef<T>(ref: React.Ref<T>, node: T) {
@@ -43,14 +43,19 @@ export function supportRef(nodeOrComponent: any): boolean {
4343
: nodeOrComponent.type;
4444

4545
// Function component node
46-
if (typeof type === 'function' && !type.prototype?.render) {
46+
if (
47+
typeof type === 'function' &&
48+
!type.prototype?.render &&
49+
type.$$typeof !== ForwardRef
50+
) {
4751
return false;
4852
}
4953

5054
// Class component
5155
if (
5256
typeof nodeOrComponent === 'function' &&
53-
!nodeOrComponent.prototype?.render
57+
!nodeOrComponent.prototype?.render &&
58+
nodeOrComponent.$$typeof !== ForwardRef
5459
) {
5560
return false;
5661
}

0 commit comments

Comments
 (0)