Skip to content

Commit

Permalink
chore: one more check for null (#602)
Browse files Browse the repository at this point in the history
  • Loading branch information
zombieJ authored Dec 11, 2024
1 parent d2a8db3 commit 850dfdc
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/ref.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ export const useComposeRef = <T>(...refs: React.Ref<T>[]): React.Ref<T> => {
};

export const supportRef = (nodeOrComponent: any): boolean => {
if (!nodeOrComponent) {
return false;
}

// React 19 no need `forwardRef` anymore. So just pass if is a React element.
if (
isReactElement(nodeOrComponent) &&
Expand Down
4 changes: 4 additions & 0 deletions tests/ref.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,10 @@ describe('ref', () => {
expect(supportRef(MemoFC)).toBeTruthy();
expect(supportRef(holderRef.current.props.children)).toBeTruthy();
});

it('skip null', () => {
expect(supportRef(null)).toBeFalsy();
});
});

describe('nodeSupportRef', () => {
Expand Down

0 comments on commit 850dfdc

Please sign in to comment.