Skip to content

Commit 7460dd5

Browse files
authored
chore: upgrade to React 19 (#2775)
* chore: compatible React 19 * fix: fix * fix: fix * fix: fix * fix: fix * fix: fix * fix: fix * fix: fix * fix: fix * fix: fix * fix: fix * fix: fix * fix: fix * fix: fix * fix: fix * fix: fix * fix: fix * fix: fix * fix: fix * fix: fix * fix: fix * fix: fix * fix: fix * fix: fix * fix: fix * fix: fix * fix: fix * fix: fix * fix: fix * fix: fix * fix: fix * fix: fix * fix: fix * fix: fix * fix: fix * fix: fix * fix: fix * fix: fix * fix: fix * fix: fix * fix: fix * fix: fix type * fix: fix type
1 parent 37ffafe commit 7460dd5

File tree

81 files changed

+3229
-3371
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

81 files changed

+3229
-3371
lines changed

package.json

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@
4343
"@testing-library/react": "^16.3.0",
4444
"@types/jest": "^29.4.0",
4545
"@types/mockjs": "^1.0.7",
46+
"@types/react": "^19.1.2",
47+
"@types/react-dom": "^19.1.3",
4648
"@types/react-router": "^5.1.19",
4749
"@umijs/fabric": "^2.1.0",
4850
"antd": "^5.14.2",
@@ -64,8 +66,8 @@
6466
"jest-environment-jsdom": "^29.4.1",
6567
"jest-localstorage-mock": "^2.4.18",
6668
"mockjs": "^1.1.0",
67-
"react": "^18.2.0",
68-
"react-dom": "^18.2.0",
69+
"react": "^19.1.0",
70+
"react-dom": "^19.1.0",
6971
"react-drag-listview": "^0.1.6",
7072
"react-router": "^6.4.2",
7173
"react-shadow": "^19.0.3",
@@ -77,6 +79,10 @@
7779
"webpack-cli": "^5.1.4",
7880
"webpack-merge": "^4.2.2"
7981
},
82+
"peerDependencies": {
83+
"react": "^16.8.0 || ^17.0.0 || ^18.0.0 || ^19.0.0",
84+
"react-dom": "^16.8.0 || ^17.0.0 || ^18.0.0 || ^19.0.0"
85+
},
8086
"commitlint": {
8187
"extends": [
8288
"@commitlint/config-conventional"

packages/hooks/package.json

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,20 +32,25 @@
3232
"screenfull": "^5.0.0",
3333
"tslib": "^2.4.1"
3434
},
35-
"peerDependencies": {
36-
"react": "^16.8.0 || ^17.0.0 || ^18.0.0 || ^19.0.0"
37-
},
3835
"devDependencies": {
3936
"@alifd/next": "^1.20.6",
4037
"@ant-design/icons": "^5.0.1",
4138
"@types/js-cookie": "^3.0.6",
4239
"@types/lodash": "^4.14.202",
40+
"@types/react": "^19.1.2",
41+
"@types/react-dom": "^19.1.3",
4342
"antd": "^5.2.1",
4443
"jest-websocket-mock": "^2.1.0",
4544
"mockjs": "^1.1.0",
45+
"react": "^19.1.0",
46+
"react-dom": "^19.1.0",
4647
"react-drag-listview": "^0.1.6",
4748
"react-json-view": "^1.21.3"
4849
},
50+
"peerDependencies": {
51+
"react": "^16.8.0 || ^17.0.0 || ^18.0.0 || ^19.0.0",
52+
"react-dom": "^16.8.0 || ^17.0.0 || ^18.0.0 || ^19.0.0"
53+
},
4954
"engines": {
5055
"node": ">=8.0.0"
5156
},

packages/hooks/src/createDeepCompareEffect/index.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,15 @@ import type { DependencyList, useEffect, useLayoutEffect } from 'react';
33
import { depsEqual } from '../utils/depsEqual';
44

55
type EffectHookType = typeof useEffect | typeof useLayoutEffect;
6+
67
type CreateUpdateEffect = (hook: EffectHookType) => EffectHookType;
78

89
export const createDeepCompareEffect: CreateUpdateEffect = (hook) => (effect, deps) => {
9-
const ref = useRef<DependencyList>();
10+
const ref = useRef<DependencyList>(undefined);
1011
const signalRef = useRef<number>(0);
11-
1212
if (deps === undefined || !depsEqual(deps, ref.current)) {
1313
signalRef.current += 1;
1414
}
1515
ref.current = deps;
16-
1716
hook(effect, [signalRef.current]);
1817
};

packages/hooks/src/useAntdTable/__tests__/index.test.ts

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import type { RenderHookResult } from '@testing-library/react';
12
import { act, renderHook, waitFor } from '@testing-library/react';
23
import { sleep } from '../../utils/testingHelpers';
34
import useAntdTable from '../index';
@@ -63,15 +64,12 @@ describe('useAntdTable', () => {
6364
searchType = type;
6465
};
6566

66-
const setUp = (service, options) => renderHook((o) => useAntdTable(service, o || options));
67+
const setUp = (
68+
service: Parameters<typeof useAntdTable>[0],
69+
options: Parameters<typeof useAntdTable>[1],
70+
) => renderHook((o) => useAntdTable(service, o || options));
6771

68-
let hook: any;
69-
70-
// afterEach(() => {
71-
// form.resetFields();
72-
// changeSearchType('simple');
73-
// hook?.unmount();
74-
// });
72+
let hook: RenderHookResult<any, any>;
7573

7674
it('should fetch after first render', async () => {
7775
queryArgs = undefined;
@@ -198,9 +196,9 @@ describe('useAntdTable', () => {
198196
getFieldInstance(key: string) {
199197
// 根据不同的 type 返回不同的 fieldsValues
200198
if (searchType === 'simple') {
201-
return ['name'].includes(key);
199+
return ['name'].includes(key) as any;
202200
}
203-
return ['name', 'email', 'phone'].includes(key);
201+
return ['name', 'email', 'phone'].includes(key) as any;
204202
},
205203
};
206204

@@ -289,7 +287,7 @@ describe('useAntdTable', () => {
289287
defaultParams: {
290288
current: 1,
291289
pageSize: 10,
292-
},
290+
} as any,
293291
defaultPageSize: 20,
294292
});
295293
});

packages/hooks/src/useControllableValue/__tests__/index.test.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
import { act, renderHook } from '@testing-library/react';
2-
import useControllableValue, { Options, Props } from '../index';
2+
import type { Options, Props } from '../index';
3+
import useControllableValue from '../index';
34

45
describe('useControllableValue', () => {
5-
const setUp = (props?: Props, options?: Options<any>): any =>
6+
const setUp = (props?: Props, options?: Options<any>) =>
67
renderHook(() => useControllableValue(props, options));
78

89
it('defaultValue should work', () => {

packages/hooks/src/useCookieState/index.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@ function useCookieState(cookieKey: string, options: Options = {}) {
1313
const [state, setState] = useState<State>(() => {
1414
const cookieValue = Cookies.get(cookieKey);
1515

16-
if (isString(cookieValue)) return cookieValue;
16+
if (isString(cookieValue)) {
17+
return cookieValue;
18+
}
1719

1820
if (isFunction(options.defaultValue)) {
1921
return options.defaultValue();
@@ -27,6 +29,7 @@ function useCookieState(cookieKey: string, options: Options = {}) {
2729
newValue: State | ((prevState: State) => State),
2830
newOptions: Cookies.CookieAttributes = {},
2931
) => {
32+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
3033
const { defaultValue, ...restOptions } = { ...options, ...newOptions };
3134
const value = isFunction(newValue) ? newValue(state) : newValue;
3235

packages/hooks/src/useCountDown/demo/demo1.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,10 @@ import React from 'react';
1010
import { useCountDown } from 'ahooks';
1111

1212
export default () => {
13-
const [countdown, formattedRes] = useCountDown({
13+
const [, formattedRes] = useCountDown({
1414
targetDate: `${new Date().getFullYear()}-12-31 23:59:59`,
1515
});
1616
const { days, hours, minutes, seconds, milliseconds } = formattedRes;
17-
1817
return (
1918
<p>
2019
There are {days} days {hours} hours {minutes} minutes {seconds} seconds {milliseconds}{' '}

packages/hooks/src/useCounter/__tests__/index.test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { act, renderHook } from '@testing-library/react';
2-
import useCounter, { Options } from '../index';
2+
import type { Options } from '../index';
3+
import useCounter from '../index';
34

45
const setUp = (init?: number, options?: Options) => renderHook(() => useCounter(init, options));
56

packages/hooks/src/useCreation/__tests__/index.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ describe('useCreation', () => {
1111
data: number;
1212
}
1313

14-
const setUp = (): any =>
14+
const setUp = () =>
1515
renderHook(() => {
1616
const [count, setCount] = useState(0);
1717
const [, setFlag] = useState({});

packages/hooks/src/useCreation/index.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,18 @@ import type { DependencyList } from 'react';
22
import { useRef } from 'react';
33
import depsAreSame from '../utils/depsAreSame';
44

5-
export default function useCreation<T>(factory: () => T, deps: DependencyList) {
5+
const useCreation = <T>(factory: () => T, deps: DependencyList) => {
66
const { current } = useRef({
77
deps,
8-
obj: undefined as undefined | T,
8+
obj: undefined as T,
99
initialized: false,
1010
});
1111
if (current.initialized === false || !depsAreSame(current.deps, deps)) {
1212
current.deps = deps;
1313
current.obj = factory();
1414
current.initialized = true;
1515
}
16-
return current.obj as T;
17-
}
16+
return current.obj;
17+
};
18+
19+
export default useCreation;

0 commit comments

Comments
 (0)