@jelper/hooks 0.1.2 → 0.2.0
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/es/index.js +110 -136
- package/lib/index.js +111 -136
- package/package.json +4 -2
- package/types/index.d.ts +20 -0
- package/types/useAsync.d.ts +13 -0
- package/types/useBoolState.d.ts +2 -0
- package/types/useCreate.d.ts +2 -0
- package/types/useDebounce.d.ts +3 -0
- package/types/useInterval.d.ts +2 -0
- package/types/useIsUnmount.d.ts +2 -0
- package/types/useListener.d.ts +2 -0
- package/types/useMount.d.ts +2 -0
- package/types/useParamsState.d.ts +6 -0
- package/types/useResizeObserver.d.ts +1 -0
- package/types/useRtCb.d.ts +2 -0
- package/types/useRtEffect.d.ts +2 -0
- package/types/useRtRef.d.ts +2 -0
- package/types/useRtState.d.ts +6 -0
- package/types/useSafeCb.d.ts +2 -0
- package/types/useSafeState.d.ts +3 -0
- package/types/useThrottle.d.ts +10 -0
- package/types/useTimeout.d.ts +8 -0
- package/types/useUnmount.d.ts +2 -0
- package/types/useUpdateEffect.d.ts +1 -0
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
interface Opt<T extends (...arg: any) => any, R> {
|
|
2
|
+
defParam?: Parameters<T>;
|
|
3
|
+
immediate?: boolean;
|
|
4
|
+
format?: (p: ReturnType<T>) => R;
|
|
5
|
+
catchParam?: boolean;
|
|
6
|
+
}
|
|
7
|
+
declare const useAsync: <T extends (...arg: any) => Promise<any>, R extends Object>(asyncFn: T, opt?: Opt<T, R>) => {
|
|
8
|
+
data: R | null | undefined;
|
|
9
|
+
run: ReturnFn<(runParam?: Partial<Parameters<T>> | undefined) => Promise<void>>;
|
|
10
|
+
loading: boolean | undefined;
|
|
11
|
+
error: null | undefined;
|
|
12
|
+
};
|
|
13
|
+
export default useAsync;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default function useResizeObserver(dom: HTMLElement, cb: (dom: ResizeObserverEntry) => void): (() => void)[];
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
interface Options<T> {
|
|
3
|
+
isEqual?: (a: T, b: T) => boolean;
|
|
4
|
+
}
|
|
5
|
+
export default function useRtState<T = any>(value: T, onChange?: (value: T) => void, opts?: Options<T>): (T | import("react").Dispatch<import("react").SetStateAction<T>>)[];
|
|
6
|
+
export {};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { ThrottleSettings } from 'lodash-es';
|
|
2
|
+
/**
|
|
3
|
+
* 用于节流函数的钩子函数
|
|
4
|
+
* @param cb - 要节流的函数
|
|
5
|
+
* @param wait - 节流延迟时间,默认为0
|
|
6
|
+
* @param opts - 节流选项对象,默认为{}
|
|
7
|
+
* @returns 节流函数
|
|
8
|
+
*/
|
|
9
|
+
declare const useThrottle: <T extends (...args: any) => any>(cb: T, wait?: number, opts?: ThrottleSettings) => import("lodash-es").DebouncedFunc<(...arg: Parameters<T>) => void>;
|
|
10
|
+
export default useThrottle;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default function useUpdateEffect(cb: () => void, deps: any[]): void;
|