react-hook-toolkit 0.0.5 → 0.0.7
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 +1 -1
- package/dist/Hooks/hooks.d.ts +194 -0
- package/dist/Hooks/hooks.js +1149 -0
- package/dist/Hooks/hooksComp.d.ts +38 -0
- package/dist/Hooks/hooksComp.js +212 -0
- package/dist/index.d.ts +4 -195
- package/dist/index.js +4 -9
- package/package.json +29 -51
- package/dist/index.js.map +0 -1
- package/dist/index.mjs +0 -9
- package/dist/index.mjs.map +0 -1
package/README.md
CHANGED
|
@@ -48,7 +48,7 @@ Install the package with npm:
|
|
|
48
48
|
|
|
49
49
|
- **`useArray<T>`**: Provides an array state with helper functions to manipulate it, including setting, adding, removing by index, and clearing elements.
|
|
50
50
|
|
|
51
|
-
- **`
|
|
51
|
+
- **`useStepper`**: Manages step-based navigation by keeping track of the current step index and providing functions to move forward, backward, and reset.
|
|
52
52
|
|
|
53
53
|
- **`useTimeoutFn`**: Executes a callback function after a specified delay and provides functions to reset or clear the timeout.
|
|
54
54
|
|
|
@@ -0,0 +1,194 @@
|
|
|
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 const useStepper: (totalSteps: number) => {
|
|
62
|
+
activeStep: number;
|
|
63
|
+
handleNext: () => void;
|
|
64
|
+
handleBack: () => void;
|
|
65
|
+
handleReset: () => void;
|
|
66
|
+
totalSteps: number;
|
|
67
|
+
isFirstStep: boolean;
|
|
68
|
+
isLastStep: boolean;
|
|
69
|
+
isProccesing: boolean;
|
|
70
|
+
setIsProccesing: import("react").Dispatch<import("react").SetStateAction<boolean>>;
|
|
71
|
+
};
|
|
72
|
+
export declare function useTimeoutFn(callback: () => void, delay: number | null): {
|
|
73
|
+
reset: () => void;
|
|
74
|
+
clear: () => void;
|
|
75
|
+
};
|
|
76
|
+
export declare function useDebouncedCallback(callback: () => void, delay: number): () => void;
|
|
77
|
+
export declare function useScrollLock(lock: boolean): void;
|
|
78
|
+
export declare function useResizeObserver<T extends HTMLElement>(ref: RefObject<T>): WindowSize | null;
|
|
79
|
+
interface MousePosition {
|
|
80
|
+
x: number;
|
|
81
|
+
y: number;
|
|
82
|
+
}
|
|
83
|
+
export declare function useMousePosition(): MousePosition;
|
|
84
|
+
type ScrollDirection = 'up' | 'down';
|
|
85
|
+
export declare function useScrollDirection(): ScrollDirection;
|
|
86
|
+
export declare function useImageLoader(src: string): {
|
|
87
|
+
loaded: boolean;
|
|
88
|
+
error: boolean;
|
|
89
|
+
};
|
|
90
|
+
export declare function usePersistedState<T>(key: string, initialValue: T): [T, React.Dispatch<React.SetStateAction<T>>];
|
|
91
|
+
export declare function useReducedMotion(): boolean;
|
|
92
|
+
export declare function useCookie(key: string): [string | null, (value: string, options?: any) => void, () => void];
|
|
93
|
+
export declare function useFetchRetry<T>(url: string, options: RequestInit, retries?: number): {
|
|
94
|
+
data: T | null;
|
|
95
|
+
error: string | null;
|
|
96
|
+
loading: boolean;
|
|
97
|
+
};
|
|
98
|
+
export declare function useDelay<T>(value: T, delay: number): T;
|
|
99
|
+
export declare function useVisibilityChange(): boolean;
|
|
100
|
+
export declare function useDebouncedValue<T>(value: T, delay: number): T;
|
|
101
|
+
export type Status = 'idle' | 'pending' | 'success' | 'error';
|
|
102
|
+
export type AsyncFunction<T> = () => Promise<T>;
|
|
103
|
+
export interface UseAsyncReturn<T> {
|
|
104
|
+
execute: () => void;
|
|
105
|
+
status: Status;
|
|
106
|
+
value: T | null;
|
|
107
|
+
error: Error | null;
|
|
108
|
+
}
|
|
109
|
+
export declare function useAsync<T>(asyncFunction: AsyncFunction<T>, immediate?: boolean): UseAsyncReturn<T>;
|
|
110
|
+
export type ScriptStatus = 'loading' | 'ready' | 'error' | 'unknown';
|
|
111
|
+
export declare function useScript(src: string, removeOnUnmount?: boolean): ScriptStatus;
|
|
112
|
+
export declare function useIndexedDB<T>(dbName: string, storeName: string): {
|
|
113
|
+
data: T | null;
|
|
114
|
+
error: Error | null;
|
|
115
|
+
};
|
|
116
|
+
export declare function useGeoLocation(): {
|
|
117
|
+
position: GeolocationPosition | null;
|
|
118
|
+
error: Error | null;
|
|
119
|
+
};
|
|
120
|
+
export declare function useTimer(initialTime: number): {
|
|
121
|
+
time: number;
|
|
122
|
+
error: Error | null;
|
|
123
|
+
};
|
|
124
|
+
export declare function useIsMounted(): boolean;
|
|
125
|
+
export declare function useCss(css: string): {
|
|
126
|
+
error: Error | null;
|
|
127
|
+
};
|
|
128
|
+
export declare function useSpeak(text: string): {
|
|
129
|
+
speak: () => void;
|
|
130
|
+
error: Error | null;
|
|
131
|
+
};
|
|
132
|
+
export declare function useCountUp(target: number, duration: number): {
|
|
133
|
+
count: number;
|
|
134
|
+
error: Error | null;
|
|
135
|
+
};
|
|
136
|
+
export declare function useCountDown(start: number): {
|
|
137
|
+
count: number;
|
|
138
|
+
error: Error | null;
|
|
139
|
+
};
|
|
140
|
+
interface BatteryState {
|
|
141
|
+
supported: boolean;
|
|
142
|
+
loading: boolean;
|
|
143
|
+
level: number | null;
|
|
144
|
+
charging: boolean | null;
|
|
145
|
+
chargingTime: number | null;
|
|
146
|
+
dischargingTime: number | null;
|
|
147
|
+
}
|
|
148
|
+
export declare const useBattery: () => BatteryState;
|
|
149
|
+
export declare const useEventListener: (eventName: string, handler: (event: Event) => void, elementRef?: React.RefObject<HTMLElement>, options?: boolean | AddEventListenerOptions) => void;
|
|
150
|
+
interface HistoryState {
|
|
151
|
+
[key: string]: any;
|
|
152
|
+
}
|
|
153
|
+
interface UseHistory {
|
|
154
|
+
history: History;
|
|
155
|
+
state: HistoryState | null;
|
|
156
|
+
push: (path: string, state?: HistoryState) => void;
|
|
157
|
+
replace: (path: string, state?: HistoryState) => void;
|
|
158
|
+
goBack: () => void;
|
|
159
|
+
goForward: () => void;
|
|
160
|
+
}
|
|
161
|
+
export declare const useHistory: () => UseHistory;
|
|
162
|
+
interface UsePreferredLanguage {
|
|
163
|
+
language: string;
|
|
164
|
+
languages: Array<string>;
|
|
165
|
+
isSupported: boolean;
|
|
166
|
+
}
|
|
167
|
+
export declare const usePreferredLanguage: () => UsePreferredLanguage;
|
|
168
|
+
interface UseSessionStorage<T> {
|
|
169
|
+
(key: string, initialValue: T): [T, (value: T) => void];
|
|
170
|
+
}
|
|
171
|
+
export declare const useSessionStorage: UseSessionStorage<any>;
|
|
172
|
+
interface UseSound {
|
|
173
|
+
play: () => void;
|
|
174
|
+
pause: () => void;
|
|
175
|
+
stop: () => void;
|
|
176
|
+
setVolume: (volume: number) => void;
|
|
177
|
+
isPlaying: boolean;
|
|
178
|
+
error: Error | null;
|
|
179
|
+
}
|
|
180
|
+
export declare const useSound: (url: string) => UseSound;
|
|
181
|
+
interface TouchPosition {
|
|
182
|
+
x: number | null;
|
|
183
|
+
y: number | null;
|
|
184
|
+
}
|
|
185
|
+
interface UseTouch {
|
|
186
|
+
(elementRef: React.RefObject<HTMLElement>): {
|
|
187
|
+
touchStart: TouchPosition;
|
|
188
|
+
touchMove: TouchPosition;
|
|
189
|
+
touchEnd: TouchPosition;
|
|
190
|
+
};
|
|
191
|
+
}
|
|
192
|
+
export declare const useTouch: UseTouch;
|
|
193
|
+
export declare const useUpdateEffect: (effect: React.EffectCallback, deps: React.DependencyList) => void;
|
|
194
|
+
export {};
|