diff --git a/src/ref.ts b/src/ref.ts index fd9513b9..9dd8c41d 100644 --- a/src/ref.ts +++ b/src/ref.ts @@ -4,7 +4,7 @@ import { ForwardRef, isMemo } from 'react-is'; import useMemo from './hooks/useMemo'; import isFragment from './React/isFragment'; -const ReactMajorVersion = Number(version.split('.')[0]); +const ReactMajorVersion = Number(version?.split('.')[0]); export const fillRef = (ref: React.Ref, node: T) => { if (typeof ref === 'function') { diff --git a/tests/ref-version.test.ts b/tests/ref-version.test.ts new file mode 100644 index 00000000..5c438909 --- /dev/null +++ b/tests/ref-version.test.ts @@ -0,0 +1,10 @@ +jest.mock('react', () => ({ + ...jest.requireActual('react'), + version: undefined, +})); + +describe('ref without a React version export', () => { + it('loads without throwing', () => { + expect(() => jest.requireActual('../src/ref')).not.toThrow(); + }); +});