Skip to content

Commit 389c571

Browse files
authored
fix: guard missing React version export (#810)
Signed-off-by: 陳廷安 <[email protected]>
1 parent 335e3cf commit 389c571

2 files changed

Lines changed: 11 additions & 1 deletion

File tree

‎src/ref.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { ForwardRef, isMemo } from 'react-is';
44
import useMemo from './hooks/useMemo';
55
import isFragment from './React/isFragment';
66

7-
const ReactMajorVersion = Number(version.split('.')[0]);
7+
const ReactMajorVersion = Number(version?.split('.')[0]);
88

99
export const fillRef = <T>(ref: React.Ref<T>, node: T) => {
1010
if (typeof ref === 'function') {

‎tests/ref-version.test.ts‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
jest.mock('react', () => ({
2+
...jest.requireActual('react'),
3+
version: undefined,
4+
}));
5+
6+
describe('ref without a React version export', () => {
7+
it('loads without throwing', () => {
8+
expect(() => jest.requireActual('../src/ref')).not.toThrow();
9+
});
10+
});

0 commit comments

Comments
 (0)