@wzyjs/hooks 0.0.27 → 0.0.30

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,2 @@
1
+ /// <reference types="react" />
2
+ export declare const useFormRef: <Values>() => import("react").MutableRefObject<any>;
@@ -0,0 +1,4 @@
1
+ import { useRef } from 'react';
2
+ export const useFormRef = () => {
3
+ return useRef();
4
+ };
@@ -1,5 +1,5 @@
1
- import { RequestRes } from '@wzyjs/utils';
2
- import { Options, Service, Result } from 'ahooks/lib/useRequest/src/types';
1
+ import { RequestRes } from '@wzyjs/types';
2
+ import { Options, Result, Service } from 'ahooks/lib/useRequest/src/types';
3
3
  interface UserOptions<P extends any[], R> extends Options<R, P> {
4
4
  alertErrorMessage?: false | string;
5
5
  alertSuccessMessage?: true | string;
@@ -7,5 +7,5 @@ interface UserOptions<P extends any[], R> extends Options<R, P> {
7
7
  interface IResult<R extends RequestRes, P extends any[]> extends Omit<Result<R, P>, 'data'> {
8
8
  data?: R['data'];
9
9
  }
10
- export declare const useRequestPro: <P extends any[], R extends RequestRes<any>>(reqPromise?: Service<R, P> | undefined, userOptions?: UserOptions<P, R> | undefined) => IResult<R, P> | null;
10
+ export declare const useRequestPro: <P extends any[], R extends RequestRes<any>>(reqPromise?: Service<R, P> | undefined, userOptions?: UserOptions<P, R> | undefined) => IResult<R, P>;
11
11
  export {};
@@ -1,19 +1,33 @@
1
1
  import { message } from 'antd';
2
- import { omit } from '@wzyjs/utils';
3
2
  import { useRequest } from 'ahooks';
3
+ import { noop, omit } from '@wzyjs/utils';
4
+ const defaultResult = {
5
+ loading: false,
6
+ data: undefined,
7
+ error: undefined,
8
+ params: [],
9
+ cancel: noop,
10
+ refresh: noop,
11
+ refreshAsync: noop,
12
+ run: noop,
13
+ runAsync: noop,
14
+ mutate: noop,
15
+ };
4
16
  export const useRequestPro = (reqPromise, userOptions) => {
5
17
  if (!reqPromise) {
6
- return null;
18
+ return defaultResult;
7
19
  }
8
20
  const { alertErrorMessage = true, alertSuccessMessage = false } = userOptions || {};
9
21
  const defaultOptions = {
22
+ cacheKey: String(reqPromise),
23
+ staleTime: 5000,
10
24
  debounceWait: 300,
11
25
  throttleWait: 300,
12
- onError: (e, params) => {
26
+ onError: (err, params) => {
13
27
  if (alertErrorMessage) {
14
- message.error(typeof alertErrorMessage === 'string' ? alertErrorMessage : e.message || '请求失败');
28
+ message.error(typeof alertErrorMessage === 'string' ? alertErrorMessage : err.message || '请求失败');
15
29
  }
16
- userOptions?.onError?.(e, params);
30
+ userOptions?.onError?.(err, params);
17
31
  },
18
32
  onSuccess: (res, params) => {
19
33
  // 如果失败,则还是调用 onError
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wzyjs/hooks",
3
- "version": "0.0.27",
3
+ "version": "0.0.30",
4
4
  "description": "description",
5
5
  "author": "wzy",
6
6
  "license": "ISC",
@@ -14,18 +14,15 @@
14
14
  "dist"
15
15
  ],
16
16
  "dependencies": {
17
- "@types/react": "^18.0.28",
18
- "@wzyjs/utils": "^0.0.27",
17
+ "@wzyjs/types": "^0.0.30",
18
+ "@wzyjs/utils": "^0.0.30",
19
19
  "ahooks": "^3.7.3",
20
- "antd": "^5.1.0",
20
+ "antd": "^5.6.2",
21
21
  "react-use": "^17.4.0"
22
22
  },
23
- "peerDependencies": {
24
- "@types/react": "latest",
25
- "react": "latest"
26
- },
27
23
  "devDependencies": {
28
- "@types/node": "^18.11.17"
24
+ "@types/node": "^18.11.17",
25
+ "@types/react": "latest"
29
26
  },
30
27
  "publishConfig": {
31
28
  "access": "public"
@@ -34,5 +31,5 @@
34
31
  "type": "git",
35
32
  "url": "https://gitee.com/wang-zhenyu/work.git"
36
33
  },
37
- "gitHead": "df22fdc32eef4bfe3a8920a1c3d048f5713bda8e"
34
+ "gitHead": "c8e042a5bb184b3842ec4f04d2edd671a0ac2802"
38
35
  }