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', () => {