react-hook-toolkit 0.0.5 → 0.0.6
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/README.md +5 -0
- package/dist/hooks/hooks.d.ts +192 -0
- package/dist/hooks/hooks.js +1140 -0
- package/dist/hooks/hooksComp.d.ts +38 -0
- package/dist/hooks/hooksComp.js +212 -0
- package/dist/index.d.ts +3 -195
- package/dist/index.js +3 -9
- package/package.json +18 -40
- package/dist/index.js.map +0 -1
- package/dist/index.mjs +0 -9
- package/dist/index.mjs.map +0 -1
package/README.md
CHANGED
|
@@ -116,6 +116,11 @@ Install the package with npm:
|
|
|
116
116
|
|
|
117
117
|
- **`useUpdateEffect`**: Executes a side effect on updates after the initial render, skipping the effect during the first render to avoid unnecessary executions.
|
|
118
118
|
|
|
119
|
+
## Authors
|
|
120
|
+
|
|
121
|
+
- **Shivaji** : (Sr. React Developer)
|
|
122
|
+
- **Shyamal** : (Sr. React Developer)
|
|
123
|
+
|
|
119
124
|
## License
|
|
120
125
|
|
|
121
126
|
[MIT](https://opensource.org/licenses)
|
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
import { RefObject } from 'react';
|
|
2
|
+
import { AxiosRequestConfig } from 'axios';
|
|
3
|
+
interface UseAxiosResponse<T> {
|
|
4
|
+
data: T | null;
|
|
5
|
+
loading: boolean;
|
|
6
|
+
error: string | null;
|
|
7
|
+
makeRequest: (url: string, method?: string, requestData?: any) => void;
|
|
8
|
+
cancelRequest: () => void;
|
|
9
|
+
}
|
|
10
|
+
interface UseAxiosConfig extends AxiosRequestConfig {
|
|
11
|
+
baseURL?: string;
|
|
12
|
+
headers?: {
|
|
13
|
+
[key: string]: string;
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
export declare const useAxios: <T>(config?: UseAxiosConfig) => UseAxiosResponse<T>;
|
|
17
|
+
export declare const useAdvReducer: <State, Action extends {
|
|
18
|
+
type: string;
|
|
19
|
+
}>(initialState: State, actions: Record<string, (state: State, action: Action) => State>) => (state: State | undefined, action: Action) => State;
|
|
20
|
+
interface FetchState<T> {
|
|
21
|
+
data: T | null;
|
|
22
|
+
loading: boolean;
|
|
23
|
+
error: string | null;
|
|
24
|
+
}
|
|
25
|
+
export declare function useFetch<T>(url: string): FetchState<T>;
|
|
26
|
+
export declare function useLocalStorage<T>(key: string, initialValue: T): [T, (value: T) => void];
|
|
27
|
+
export declare function useToggle(initialValue?: boolean): [boolean, () => void];
|
|
28
|
+
export declare function useDebounce<T>(value: T, delay: number): T;
|
|
29
|
+
export declare function useThrottle<T>(value: T, limit: number): T;
|
|
30
|
+
export declare function usePrevious<T>(value: T): T | undefined;
|
|
31
|
+
export declare function useMediaQuery(query: string): boolean;
|
|
32
|
+
export declare function useClipboard(): [boolean, (text: string) => Promise<void>];
|
|
33
|
+
export declare function useInterval(callback: () => void, delay: number | null): void;
|
|
34
|
+
interface WindowSize {
|
|
35
|
+
width: number;
|
|
36
|
+
height: number;
|
|
37
|
+
}
|
|
38
|
+
export declare function useWindowSize(): WindowSize;
|
|
39
|
+
export declare function useKeyPress(targetKey: string): boolean;
|
|
40
|
+
export declare function useOnlineStatus(): boolean;
|
|
41
|
+
interface ScrollPosition {
|
|
42
|
+
x: number;
|
|
43
|
+
y: number;
|
|
44
|
+
}
|
|
45
|
+
export declare function useScrollPosition(): ScrollPosition;
|
|
46
|
+
export declare function useTimeout(callback: () => void, delay: number | null): void;
|
|
47
|
+
export declare function useDarkMode(): [boolean, () => void];
|
|
48
|
+
export declare function useForm<T extends Record<string, any>>(initialValues: T): {
|
|
49
|
+
values: T;
|
|
50
|
+
errors: Partial<Record<keyof T, string>>;
|
|
51
|
+
handleChange: (name: keyof T, value: any) => void;
|
|
52
|
+
validate: (validators: Partial<Record<keyof T, (value: any) => string | null>>) => boolean;
|
|
53
|
+
};
|
|
54
|
+
export declare function useArray<T>(initialArray: T[]): {
|
|
55
|
+
array: T[];
|
|
56
|
+
set: import("react").Dispatch<import("react").SetStateAction<T[]>>;
|
|
57
|
+
push: (item: T) => void;
|
|
58
|
+
removeByIndex: (index: number) => void;
|
|
59
|
+
clear: () => void;
|
|
60
|
+
};
|
|
61
|
+
export declare function useStep<T>(steps: T[]): {
|
|
62
|
+
currentStep: T;
|
|
63
|
+
currentStepIndex: number;
|
|
64
|
+
next: () => void;
|
|
65
|
+
previous: () => void;
|
|
66
|
+
reset: () => void;
|
|
67
|
+
isFirstStep: boolean;
|
|
68
|
+
isLastStep: boolean;
|
|
69
|
+
};
|
|
70
|
+
export declare function useTimeoutFn(callback: () => void, delay: number | null): {
|
|
71
|
+
reset: () => void;
|
|
72
|
+
clear: () => void;
|
|
73
|
+
};
|
|
74
|
+
export declare function useDebouncedCallback(callback: () => void, delay: number): () => void;
|
|
75
|
+
export declare function useScrollLock(lock: boolean): void;
|
|
76
|
+
export declare function useResizeObserver<T extends HTMLElement>(ref: RefObject<T>): WindowSize | null;
|
|
77
|
+
interface MousePosition {
|
|
78
|
+
x: number;
|
|
79
|
+
y: number;
|
|
80
|
+
}
|
|
81
|
+
export declare function useMousePosition(): MousePosition;
|
|
82
|
+
type ScrollDirection = 'up' | 'down';
|
|
83
|
+
export declare function useScrollDirection(): ScrollDirection;
|
|
84
|
+
export declare function useImageLoader(src: string): {
|
|
85
|
+
loaded: boolean;
|
|
86
|
+
error: boolean;
|
|
87
|
+
};
|
|
88
|
+
export declare function usePersistedState<T>(key: string, initialValue: T): [T, React.Dispatch<React.SetStateAction<T>>];
|
|
89
|
+
export declare function useReducedMotion(): boolean;
|
|
90
|
+
export declare function useCookie(key: string): [string | null, (value: string, options?: any) => void, () => void];
|
|
91
|
+
export declare function useFetchRetry<T>(url: string, options: RequestInit, retries?: number): {
|
|
92
|
+
data: T | null;
|
|
93
|
+
error: string | null;
|
|
94
|
+
loading: boolean;
|
|
95
|
+
};
|
|
96
|
+
export declare function useDelay<T>(value: T, delay: number): T;
|
|
97
|
+
export declare function useVisibilityChange(): boolean;
|
|
98
|
+
export declare function useDebouncedValue<T>(value: T, delay: number): T;
|
|
99
|
+
export type Status = 'idle' | 'pending' | 'success' | 'error';
|
|
100
|
+
export type AsyncFunction<T> = () => Promise<T>;
|
|
101
|
+
export interface UseAsyncReturn<T> {
|
|
102
|
+
execute: () => void;
|
|
103
|
+
status: Status;
|
|
104
|
+
value: T | null;
|
|
105
|
+
error: Error | null;
|
|
106
|
+
}
|
|
107
|
+
export declare function useAsync<T>(asyncFunction: AsyncFunction<T>, immediate?: boolean): UseAsyncReturn<T>;
|
|
108
|
+
export type ScriptStatus = 'loading' | 'ready' | 'error' | 'unknown';
|
|
109
|
+
export declare function useScript(src: string, removeOnUnmount?: boolean): ScriptStatus;
|
|
110
|
+
export declare function useIndexedDB<T>(dbName: string, storeName: string): {
|
|
111
|
+
data: T | null;
|
|
112
|
+
error: Error | null;
|
|
113
|
+
};
|
|
114
|
+
export declare function useGeoLocation(): {
|
|
115
|
+
position: GeolocationPosition | null;
|
|
116
|
+
error: Error | null;
|
|
117
|
+
};
|
|
118
|
+
export declare function useTimer(initialTime: number): {
|
|
119
|
+
time: number;
|
|
120
|
+
error: Error | null;
|
|
121
|
+
};
|
|
122
|
+
export declare function useIsMounted(): boolean;
|
|
123
|
+
export declare function useCss(css: string): {
|
|
124
|
+
error: Error | null;
|
|
125
|
+
};
|
|
126
|
+
export declare function useSpeak(text: string): {
|
|
127
|
+
speak: () => void;
|
|
128
|
+
error: Error | null;
|
|
129
|
+
};
|
|
130
|
+
export declare function useCountUp(target: number, duration: number): {
|
|
131
|
+
count: number;
|
|
132
|
+
error: Error | null;
|
|
133
|
+
};
|
|
134
|
+
export declare function useCountDown(start: number): {
|
|
135
|
+
count: number;
|
|
136
|
+
error: Error | null;
|
|
137
|
+
};
|
|
138
|
+
interface BatteryState {
|
|
139
|
+
supported: boolean;
|
|
140
|
+
loading: boolean;
|
|
141
|
+
level: number | null;
|
|
142
|
+
charging: boolean | null;
|
|
143
|
+
chargingTime: number | null;
|
|
144
|
+
dischargingTime: number | null;
|
|
145
|
+
}
|
|
146
|
+
export declare const useBattery: () => BatteryState;
|
|
147
|
+
export declare const useEventListener: (eventName: string, handler: (event: Event) => void, elementRef?: React.RefObject<HTMLElement>, options?: boolean | AddEventListenerOptions) => void;
|
|
148
|
+
interface HistoryState {
|
|
149
|
+
[key: string]: any;
|
|
150
|
+
}
|
|
151
|
+
interface UseHistory {
|
|
152
|
+
history: History;
|
|
153
|
+
state: HistoryState | null;
|
|
154
|
+
push: (path: string, state?: HistoryState) => void;
|
|
155
|
+
replace: (path: string, state?: HistoryState) => void;
|
|
156
|
+
goBack: () => void;
|
|
157
|
+
goForward: () => void;
|
|
158
|
+
}
|
|
159
|
+
export declare const useHistory: () => UseHistory;
|
|
160
|
+
interface UsePreferredLanguage {
|
|
161
|
+
language: string;
|
|
162
|
+
languages: Array<string>;
|
|
163
|
+
isSupported: boolean;
|
|
164
|
+
}
|
|
165
|
+
export declare const usePreferredLanguage: () => UsePreferredLanguage;
|
|
166
|
+
interface UseSessionStorage<T> {
|
|
167
|
+
(key: string, initialValue: T): [T, (value: T) => void];
|
|
168
|
+
}
|
|
169
|
+
export declare const useSessionStorage: UseSessionStorage<any>;
|
|
170
|
+
interface UseSound {
|
|
171
|
+
play: () => void;
|
|
172
|
+
pause: () => void;
|
|
173
|
+
stop: () => void;
|
|
174
|
+
setVolume: (volume: number) => void;
|
|
175
|
+
isPlaying: boolean;
|
|
176
|
+
error: Error | null;
|
|
177
|
+
}
|
|
178
|
+
export declare const useSound: (url: string) => UseSound;
|
|
179
|
+
interface TouchPosition {
|
|
180
|
+
x: number | null;
|
|
181
|
+
y: number | null;
|
|
182
|
+
}
|
|
183
|
+
interface UseTouch {
|
|
184
|
+
(elementRef: React.RefObject<HTMLElement>): {
|
|
185
|
+
touchStart: TouchPosition;
|
|
186
|
+
touchMove: TouchPosition;
|
|
187
|
+
touchEnd: TouchPosition;
|
|
188
|
+
};
|
|
189
|
+
}
|
|
190
|
+
export declare const useTouch: UseTouch;
|
|
191
|
+
export declare const useUpdateEffect: (effect: React.EffectCallback, deps: React.DependencyList) => void;
|
|
192
|
+
export {};
|