@wzyjs/hooks 0.0.17 → 0.0.18

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.
package/dist/index.d.ts CHANGED
@@ -1,3 +1,7 @@
1
1
  export * from 'ahooks';
2
- export { useCopyToClipboard, useCookie } from 'react-use';
2
+ export { useCopyToClipboard, useCookie, useUpdate } from 'react-use';
3
3
  export * from './useRequestPro';
4
+ export * from './useEffectValue';
5
+ export * from './useElementScrollVisible';
6
+ export * from './useHideFooter';
7
+ export * from './useVisibleInfo';
package/dist/index.js CHANGED
@@ -1,3 +1,7 @@
1
1
  export * from 'ahooks';
2
- export { useCopyToClipboard, useCookie } from 'react-use';
2
+ export { useCopyToClipboard, useCookie, useUpdate } from 'react-use';
3
3
  export * from './useRequestPro';
4
+ export * from './useEffectValue';
5
+ export * from './useElementScrollVisible';
6
+ export * from './useHideFooter';
7
+ export * from './useVisibleInfo';
@@ -0,0 +1 @@
1
+ export declare const useEffectValue: (fn: any, deps?: never[]) => (import("react").Dispatch<import("react").SetStateAction<undefined>> | undefined)[];
@@ -0,0 +1,6 @@
1
+ import { useEffect, useState } from 'react';
2
+ export const useEffectValue = (fn, deps = []) => {
3
+ const [value, setValue] = useState();
4
+ useEffect(() => setValue(fn()), deps);
5
+ return [value, setValue];
6
+ };
@@ -0,0 +1,5 @@
1
+ export declare const useElementScrollVisible: (scroll: any, target: any) => {
2
+ visible: boolean;
3
+ direction: string;
4
+ rect: string;
5
+ };
@@ -0,0 +1,36 @@
1
+ import { useEffect, useState } from 'react';
2
+ // 判断某元素滚动时,指定元素是否显示
3
+ export const useElementScrollVisible = (scroll, target) => {
4
+ const $scroll = document.querySelector(scroll) || {};
5
+ const $scrollRect = $scroll.getBoundingClientRect();
6
+ const [visible, setVisible] = useState(false);
7
+ const [direction, setDirection] = useState('');
8
+ const [rect, setRect] = useState('');
9
+ useEffect(() => {
10
+ const fn = () => {
11
+ const $target = document.querySelector(target) || {};
12
+ const rect = $target.getBoundingClientRect();
13
+ setRect(rect);
14
+ if (rect.bottom < $scrollRect.top) {
15
+ setDirection('top');
16
+ setVisible(false);
17
+ }
18
+ else if (rect.top > $scrollRect.bottom) {
19
+ setDirection('bottom');
20
+ setVisible(false);
21
+ }
22
+ else {
23
+ setDirection('show');
24
+ setVisible(true);
25
+ }
26
+ };
27
+ fn();
28
+ $scroll.addEventListener('scroll', fn);
29
+ return () => $scroll.removeEventListener('scroll', fn);
30
+ }, []);
31
+ return {
32
+ visible,
33
+ direction,
34
+ rect,
35
+ };
36
+ };
@@ -0,0 +1 @@
1
+ export declare const useHideFooter: (el?: string) => void;
@@ -0,0 +1,11 @@
1
+ import { useEffect } from 'react';
2
+ // 进入时隐藏指定元素,销毁时恢复该元素
3
+ export const useHideFooter = (el = '.ant-layout-footer') => {
4
+ useEffect(() => {
5
+ const e = document.querySelector(el);
6
+ e.style.display = 'none';
7
+ return () => {
8
+ e.style.display = 'block';
9
+ };
10
+ }, []);
11
+ };
@@ -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>, userOptions: UserOptions<P, R>) => IResult<R, P>;
10
+ export declare const useRequestPro: <P extends any[], R extends RequestRes<any>>(reqPromise: Service<R, P>, userOptions?: UserOptions<P, R> | undefined) => IResult<R, P>;
11
11
  export {};
@@ -2,7 +2,7 @@ import { message } from 'antd';
2
2
  import { omit } from '@wzyjs/utils';
3
3
  import { useRequest } from 'ahooks';
4
4
  export const useRequestPro = (reqPromise, userOptions) => {
5
- const { alertErrorMessage = true, alertSuccessMessage = false } = userOptions;
5
+ const { alertErrorMessage = true, alertSuccessMessage = false } = userOptions || {};
6
6
  const defaultOptions = {
7
7
  debounceWait: 300,
8
8
  throttleWait: 300,
@@ -29,6 +29,6 @@ export const useRequestPro = (reqPromise, userOptions) => {
29
29
  const options = Object.assign(defaultOptions, omit(userOptions, ['onSuccess', 'onError']));
30
30
  // 取出 data 里的 data
31
31
  const state = useRequest(reqPromise, options);
32
- state.data = state.data?.data;
32
+ state.data = state.data?.data || state.data;
33
33
  return state;
34
34
  };
@@ -0,0 +1 @@
1
+ export declare const useStateCallback: (od: any) => any[];
@@ -0,0 +1,12 @@
1
+ import { useState, useRef, useEffect } from 'react';
2
+ export const useStateCallback = (od) => {
3
+ const cbRef = useRef();
4
+ const [data, setData] = useState(od);
5
+ useEffect(() => {
6
+ cbRef.current && cbRef.current(data);
7
+ }, [data]);
8
+ return [data, function (d, callback) {
9
+ cbRef.current = callback;
10
+ setData(d);
11
+ }];
12
+ };
@@ -0,0 +1,5 @@
1
+ export declare const useVisibleInfo: (v: boolean | undefined, i: any) => (boolean | any[] | {
2
+ setTrue: () => void;
3
+ setFalse: () => void;
4
+ toggle: () => void;
5
+ })[];
@@ -0,0 +1,18 @@
1
+ import { useState } from 'react';
2
+ // visible和info的集合体
3
+ export const useVisibleInfo = (v = false, i) => {
4
+ const [visible, setVisible] = useState(v);
5
+ const [info, setInfo] = useState(i);
6
+ return [
7
+ visible,
8
+ {
9
+ setTrue: () => setVisible(true),
10
+ setFalse: () => setVisible(false),
11
+ toggle: () => setVisible(!visible),
12
+ },
13
+ [
14
+ info,
15
+ setInfo,
16
+ ],
17
+ ];
18
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wzyjs/hooks",
3
- "version": "0.0.17",
3
+ "version": "0.0.18",
4
4
  "description": "description",
5
5
  "author": "wzy",
6
6
  "license": "ISC",
@@ -14,11 +14,16 @@
14
14
  "dist"
15
15
  ],
16
16
  "dependencies": {
17
- "@wzyjs/utils": "^0.0.17",
17
+ "@types/react": "^18.0.28",
18
+ "@wzyjs/utils": "^0.0.18",
18
19
  "ahooks": "^3.7.3",
19
20
  "antd": "^5.1.0",
20
21
  "react-use": "^17.4.0"
21
22
  },
23
+ "peerDependencies": {
24
+ "@types/react": "latest",
25
+ "react": "latest"
26
+ },
22
27
  "devDependencies": {
23
28
  "@types/node": "^18.11.17"
24
29
  },
@@ -29,5 +34,5 @@
29
34
  "type": "git",
30
35
  "url": "https://gitee.com/wang-zhenyu/work.git"
31
36
  },
32
- "gitHead": "f07be747da894f607f30c2be97c23abac5712bc2"
37
+ "gitHead": "7ebb80ef50a4df3d262a1da82d7967e628698b10"
33
38
  }