Skip to content

Commit 7160e63

Browse files
author
chj_damon
committed
chore: 不使用umi预装包,自己安装需要的插件
新增useRefCallback hook
1 parent 366c64a commit 7160e63

File tree

6 files changed

+339
-3885
lines changed

6 files changed

+339
-3885
lines changed

config/config.prod.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@ export default defineConfig({
66
dynamicImport: {
77
loading: '@/components/LoadingPage/index',
88
},
9+
outputPath: 'build',
10+
antd: {},
11+
esbuild: {},
912
dynamicImportSyntax: {},
1013
hash: true,
11-
outputPath: 'build',
1214
routes: routeConfig,
13-
esbuild: {},
14-
layout: false,
1515
metas: [
1616
{ name: 'msapplication-TileColor', content: '#da532c' },
1717
{ name: 'theme-color', content: '#ffffff' },

config/config.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@ import AntdDayjsWebpackPlugin from 'antd-dayjs-webpack-plugin';
33
import routeConfig from './routeConfig';
44

55
export default defineConfig({
6+
antd: {},
7+
esbuild: {},
68
dynamicImportSyntax: {},
79
hash: true,
810
outputPath: 'build',
911
routes: routeConfig,
10-
esbuild: {},
11-
layout: false,
1212
metas: [
1313
{ name: 'msapplication-TileColor', content: '#da532c' },
1414
{ name: 'theme-color', content: '#ffffff' },

package.json

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,16 @@
4747
"dependencies": {
4848
"@ant-design/pro-form": "^1.18.1",
4949
"@ant-design/pro-layout": "^6.5.0",
50-
"@umijs/preset-react": "1.x",
50+
"@umijs/plugin-access": "^2.3.3",
51+
"@umijs/plugin-antd": "^0.9.1",
52+
"@umijs/plugin-initial-state": "^2.3.0",
53+
"@umijs/plugin-model": "^2.5.6",
5154
"classnames": "^2.2.6",
55+
"dayjs": "^1.10.4",
5256
"react": "^17.0.1",
5357
"react-dom": "^17.0.1",
54-
"umi": "^3.4.2"
58+
"umi": "^3.4.2",
59+
"umi-request": "^1.3.5"
5560
},
5661
"devDependencies": {
5762
"@commitlint/cli": "^12.0.1",

src/hooks/useRefCallback.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { useCallback, useRef } from 'react';
2+
3+
/**
4+
* 将函数挂到 ref 上,保证永远都是拿到最新状态的函数,往外暴露时使用 useCallback 包裹,保证函数引用不更新
5+
* @param callback
6+
* @returns
7+
*/
8+
export default function useRefCallback<T extends (...args: any[]) => any>(callback: T) {
9+
const callbackRef = useRef(callback);
10+
callbackRef.current = callback;
11+
12+
return useCallback((...args: any[]) => callbackRef.current(...args), []) as T;
13+
}

src/hooks/useToast.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import { useCallback } from 'react';
33

44
export default function useToast() {
55
const toastSuccess = useCallback((msg: string) => message.success(msg), []);
6-
76
const toastFailure = useCallback((msg: string) => message.error(msg), []);
87

98
return {

0 commit comments

Comments
 (0)