From 850dfdc8691689f16ae78f00f0144719000dc60c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BA=8C=E8=B4=A7=E7=88=B1=E5=90=83=E7=99=BD=E8=90=9D?= =?UTF-8?q?=E5=8D=9C?= Date: Wed, 11 Dec 2024 12:00:26 +0800 Subject: [PATCH] chore: one more check for null (#602) --- src/ref.ts | 4 ++++ tests/ref.test.tsx | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/src/ref.ts b/src/ref.ts index 0cfb6ef0..35170714 100644 --- a/src/ref.ts +++ b/src/ref.ts @@ -36,6 +36,10 @@ export const useComposeRef = (...refs: React.Ref[]): React.Ref => { }; 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) && diff --git a/tests/ref.test.tsx b/tests/ref.test.tsx index 1f892234..8f7334ac 100644 --- a/tests/ref.test.tsx +++ b/tests/ref.test.tsx @@ -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', () => {