Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions docs/examples/getScrollBarSize.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ const cssText = `
`;

export default () => {
const defaultRef = React.useRef<HTMLDivElement>();
const webkitRef = React.useRef<HTMLDivElement>();
const scrollRef = React.useRef<HTMLDivElement>();
const defaultRef = React.useRef<HTMLDivElement>(null);
const webkitRef = React.useRef<HTMLDivElement>(null);
const scrollRef = React.useRef<HTMLDivElement>(null);
const [sizeData, setSizeData] = React.useState('');

React.useEffect(() => {
Expand Down
6 changes: 3 additions & 3 deletions docs/examples/portal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ import React from 'react';
import PortalWrapper from 'rc-util/es/PortalWrapper';

export default () => {
const divRef = React.useRef();
const outerRef = React.useRef();
const divRef = React.useRef<HTMLDivElement>(null);
const outerRef = React.useRef<HTMLDivElement>(null);

React.useEffect(() => {
console.log('>>>', divRef.current);
}, []);

function getRef() {
return outerRef.current;
}
Expand Down
14 changes: 6 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,17 +39,17 @@
},
"dependencies": {
"is-mobile": "^5.0.0",
"react-is": "^18.2.0"
"react-is": "^19.2.0"
},
"devDependencies": {
"@rc-component/father-plugin": "^2.0.1",
"@rc-component/np": "^1.0.3",
"@testing-library/react": "^16.0.0",
"@types/jest": "^30.0.0",
"@types/node": "^24.6.1",
"@types/react": "^18.0.0",
"@types/react-dom": "^18.0.0",
"@types/react-is": "^19.0.0",
"@types/react": "^19.2.0",
"@types/react-dom": "^19.2.0",
"@types/react-is": "^19.2.0",
"@types/responselike": "^1.0.0",
"@types/warning": "^3.0.0",
"@umijs/fabric": "^3.0.0",
Expand All @@ -64,10 +64,8 @@
"lint-staged": "^15.1.0",
"prettier": "^3.3.2",
"rc-test": "^7.0.14",
"react": "^18.0.0",
"react-19": "npm:[email protected]",
"react-dom": "^18.0.0",
"react-dom-19": "npm:[email protected]",
"react": "^19.2.0",
"react-dom": "^19.2.0",
"typescript": "^5.3.2"
},
"peerDependencies": {
Expand Down
4 changes: 2 additions & 2 deletions src/Portal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ export interface PortalProps {
const Portal = forwardRef<PortalRef, PortalProps>((props, ref) => {
const { didUpdate, getContainer, children } = props;

const parentRef = useRef<ParentNode>();
const containerRef = useRef<HTMLElement>();
const parentRef = useRef<ParentNode>(null);
const containerRef = useRef<HTMLElement>(null);

// Ref return nothing, only for wrapper check exist
useImperativeHandle(ref, () => ({}));
Expand Down
3 changes: 2 additions & 1 deletion src/hooks/useEvent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
import * as React from 'react';

function useEvent<T extends Function>(callback: T): T {
const fnRef = React.useRef<any>();
const fnRef = React.useRef<T>(null);

fnRef.current = callback;

const memoFn = React.useCallback<T>(
Expand Down
60 changes: 0 additions & 60 deletions tests/hooks-17.test.tsx

This file was deleted.

22 changes: 1 addition & 21 deletions tests/ref-19.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,6 @@ import React from 'react';
import { getNodeRef, useComposeRef, supportRef } from '../src/ref';
import { render } from '@testing-library/react';

jest.mock('react', () => {
const react19 = jest.requireActual('react-19');
return react19;
});

jest.mock('react-dom', () => {
const reactDom19 = jest.requireActual('react-dom-19');
return reactDom19;
});

jest.mock('react-dom/client', () => {
const reactDom19Client = jest.requireActual('react-dom-19/client');
return reactDom19Client;
});

jest.mock('react-dom/test-utils', () => {
const reactDom19Test = jest.requireActual('react-dom-19/test-utils');
return reactDom19Test;
});

describe('ref: React 19', () => {
const errSpy = jest.spyOn(console, 'error');

Expand Down Expand Up @@ -59,7 +39,7 @@ describe('ref: React 19', () => {

return (
<>
{React.cloneElement(children, { ref: mergedRef })}
{React.cloneElement<any>(children, { ref: mergedRef })}
<div className="test-output">{childClassName}</div>
</>
);
Expand Down
12 changes: 6 additions & 6 deletions tests/ref.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,9 @@ describe('ref', () => {
const Demo = () => {
const [, forceUpdate] = React.useState({});

const ref1 = React.useRef();
const ref2 = React.useRef();
const ref1 = React.useRef<HTMLButtonElement>(null);
const ref2 = React.useRef<HTMLButtonElement>(null);

const refFn = useEvent(() => {
count += 1;
});
Expand Down Expand Up @@ -102,7 +103,6 @@ describe('ref', () => {
</Holder>,
);
expect(supportRef(FC)).toBeFalsy();
// expect(supportRef(holderRef.current.props.children)).toBeFalsy();
});

it('arrow function component', () => {
Expand All @@ -116,7 +116,7 @@ describe('ref', () => {
</Holder>,
);
expect(supportRef(FC)).toBeFalsy();
expect(supportRef(holderRef.current.props.children)).toBeFalsy();
expect(supportRef(holderRef.current.props.children)).toBeTruthy(); // React19 ref 收拢到了 props 里面,默认支持
});

it('forwardRef function component', () => {
Expand Down Expand Up @@ -162,7 +162,7 @@ describe('ref', () => {
</Holder>,
);
expect(supportRef(MemoFC)).toBeFalsy();
expect(supportRef(holderRef.current.props.children)).toBeFalsy();
expect(supportRef(holderRef.current.props.children)).toBeTruthy(); // React19 ref 收拢到了 props 里面,默认支持
});

it('memo of forwardRef function component', () => {
Expand Down Expand Up @@ -195,7 +195,7 @@ describe('ref', () => {
it('FC', () => {
const FC = () => <div />;
const RefFC = React.forwardRef(FC);
expect(supportNodeRef(<FC />)).toBeFalsy();
expect(supportNodeRef(<FC />)).toBeTruthy(); // React19 ref 收拢到了 props 里面,默认支持
expect(supportNodeRef(<RefFC />)).toBeTruthy();
});

Expand Down
24 changes: 1 addition & 23 deletions tests/toArray-19.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,7 @@ import React from 'react';
import { render } from '@testing-library/react';
import toArray from '../src/Children/toArray';

jest.mock('react', () => {
const react19 = jest.requireActual('react-19');
return react19;
});

jest.mock('react-dom', () => {
const reactDom19 = jest.requireActual('react-dom-19');
return reactDom19;
});

jest.mock('react-dom/client', () => {
const reactDom19Client = jest.requireActual('react-dom-19/client');
return reactDom19Client;
});

jest.mock('react-dom/test-utils', () => {
const reactDom19Test = jest.requireActual('react-dom-19/test-utils');
return reactDom19Test;
});

class UL extends React.Component<{
children?: React.ReactNode;
}> {
class UL extends React.Component<React.PropsWithChildren<any>> {
render() {
return <ul>{this.props.children}</ul>;
}
Expand Down
Loading