Skip to content

Commit

Permalink
fix: supportRef function for preact (#477)
Browse files Browse the repository at this point in the history
  • Loading branch information
SpaNb4 committed Feb 20, 2024
1 parent 550721c commit 60c3785
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/ref.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* eslint-disable no-param-reassign */
import type * as React from 'react';
import { isValidElement, ReactNode } from 'react';
import { isFragment, isMemo } from 'react-is';
import { ForwardRef, isFragment, isMemo } from 'react-is';
import useMemo from './hooks/useMemo';

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

// Function component node
if (typeof type === 'function' && !type.prototype?.render) {
if (
typeof type === 'function' &&
!type.prototype?.render &&
type.$$typeof !== ForwardRef
) {
return false;
}

// Class component
if (
typeof nodeOrComponent === 'function' &&
!nodeOrComponent.prototype?.render
!nodeOrComponent.prototype?.render &&
nodeOrComponent.$$typeof !== ForwardRef
) {
return false;
}
Expand Down

0 comments on commit 60c3785

Please sign in to comment.