Skip to content

Commit

Permalink
fix: fix
Browse files Browse the repository at this point in the history
  • Loading branch information
li-jia-nan committed Sep 20, 2023
1 parent b9533f4 commit 6aaf0c2
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 16 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
"@types/jest": "^25.2.3",
"@types/react": "^18.0.0",
"@types/react-dom": "^18.0.0",
"@types/react-is": "^18.2.1",
"@types/responselike": "^1.0.0",
"@types/warning": "^3.0.0",
"@umijs/fabric": "^3.0.0",
Expand Down
27 changes: 11 additions & 16 deletions src/ref.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
/* eslint-disable no-param-reassign */
import type * as React from 'react';
import { isValidElement, ReactNode } from 'react';
import { isFragment, isMemo } from 'react-is';
import React from 'react';
import { isForwardRef, isFragment, isMemo } from 'react-is';
import useMemo from './hooks/useMemo';

export function fillRef<T>(ref: React.Ref<T>, node: T) {
Expand Down Expand Up @@ -37,11 +36,13 @@ export function useComposeRef<T>(...refs: React.Ref<T>[]): React.Ref<T> {
);
}

interface WithRef {
ref: React.Ref<any>;
}

export function supportRef(nodeOrComponent: any): nodeOrComponent is WithRef {
export function supportRef(nodeOrComponent: any) {
if (isFragment(nodeOrComponent)) {
return false;
}
if (isForwardRef(nodeOrComponent)) {
return true;
}
const type = isMemo(nodeOrComponent)
? nodeOrComponent.type.type
: nodeOrComponent.type;
Expand All @@ -62,15 +63,9 @@ export function supportRef(nodeOrComponent: any): nodeOrComponent is WithRef {
return true;
}

export function supportNodeRef(node: ReactNode): boolean {
if (!isValidElement(node)) {
export function supportNodeRef(node: React.ReactNode) {
if (!React.isValidElement(node)) {
return false;
}

if (isFragment(node)) {
return false;
}

return supportRef(node);
}
/* eslint-enable */

0 comments on commit 6aaf0c2

Please sign in to comment.