@ts-hooks-kit/core 0.1.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/LICENSE +23 -0
- package/README.md +146 -0
- package/dist/index.cjs +2574 -0
- package/dist/index.d.cts +1688 -0
- package/dist/index.d.ts +1688 -0
- package/dist/index.js +2499 -0
- package/package.json +78 -0
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,1688 @@
|
|
|
1
|
+
import { Dispatch, RefObject, SetStateAction, useEffect } from "react";
|
|
2
|
+
|
|
3
|
+
//#region src/useAsync/useAsync.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* Represents the state of an async operation.
|
|
6
|
+
* @template T - The type of the resolved value.
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* Represents the state of an async operation.
|
|
10
|
+
* @template T - The type of the resolved value.
|
|
11
|
+
*/
|
|
12
|
+
type UseAsyncState<T> = {
|
|
13
|
+
/** Whether the async operation is in progress. */
|
|
14
|
+
loading: boolean;
|
|
15
|
+
/** The resolved value if the operation succeeded. */
|
|
16
|
+
value: T | undefined;
|
|
17
|
+
/** The error if the operation failed. */
|
|
18
|
+
error: Error | undefined;
|
|
19
|
+
/** Function to retry the async operation. */
|
|
20
|
+
retry: () => void;
|
|
21
|
+
};
|
|
22
|
+
/**
|
|
23
|
+
* Custom hook that manages the state of an async function.
|
|
24
|
+
* @template T - The type of the resolved value.
|
|
25
|
+
* @param {() => Promise<T>} asyncFn - The async function to execute.
|
|
26
|
+
* @param {unknown[]} [deps] - Dependencies that trigger re-execution when changed.
|
|
27
|
+
* @returns {UseAsyncState<T>} The state of the async operation.
|
|
28
|
+
* @public
|
|
29
|
+
* @see [Documentation](https://usehooks-ts.com/react-hook/use-async)
|
|
30
|
+
* @example
|
|
31
|
+
* ```tsx
|
|
32
|
+
* const { value, error, loading, retry } = useAsync(async () => {
|
|
33
|
+
* const response = await fetch('/api/data');
|
|
34
|
+
* return response.json();
|
|
35
|
+
* }, []);
|
|
36
|
+
* ```
|
|
37
|
+
*/
|
|
38
|
+
declare function useAsync<T>(asyncFn: () => Promise<T>, deps?: unknown[]): UseAsyncState<T>;
|
|
39
|
+
|
|
40
|
+
//#endregion
|
|
41
|
+
//#region src/useBoolean/useBoolean.d.ts
|
|
42
|
+
/** The useBoolean return type. */
|
|
43
|
+
type UseBooleanReturn = {
|
|
44
|
+
/** The current boolean state value. */
|
|
45
|
+
value: boolean;
|
|
46
|
+
/** Function to set the boolean state directly. */
|
|
47
|
+
setValue: Dispatch<SetStateAction<boolean>>;
|
|
48
|
+
/** Function to set the boolean state to `true`. */
|
|
49
|
+
setTrue: () => void;
|
|
50
|
+
/** Function to set the boolean state to `false`. */
|
|
51
|
+
setFalse: () => void;
|
|
52
|
+
/** Function to toggle the boolean state. */
|
|
53
|
+
toggle: () => void;
|
|
54
|
+
};
|
|
55
|
+
/**
|
|
56
|
+
* Custom hook that handles boolean state with useful utility functions.
|
|
57
|
+
* @param {boolean} [defaultValue] - The initial value for the boolean state (default is `false`).
|
|
58
|
+
* @returns {UseBooleanReturn} An object containing the boolean state value and utility functions to manipulate the state.
|
|
59
|
+
* @throws Will throw an error if `defaultValue` is an invalid boolean value.
|
|
60
|
+
* @public
|
|
61
|
+
* @see [Documentation](https://usehooks-ts.com/react-hook/use-boolean)
|
|
62
|
+
* @example
|
|
63
|
+
* ```tsx
|
|
64
|
+
* const { value, setTrue, setFalse, toggle } = useBoolean(true);
|
|
65
|
+
* ```
|
|
66
|
+
*/
|
|
67
|
+
declare function useBoolean(defaultValue?: boolean): UseBooleanReturn;
|
|
68
|
+
|
|
69
|
+
//#endregion
|
|
70
|
+
//#region src/useClickAnyWhere/useClickAnyWhere.d.ts
|
|
71
|
+
/**
|
|
72
|
+
* Custom hook that handles click events anywhere on the document.
|
|
73
|
+
* @param {Function} handler - The function to be called when a click event is detected anywhere on the document.
|
|
74
|
+
* @public
|
|
75
|
+
* @see [Documentation](https://usehooks-ts.com/react-hook/use-click-any-where)
|
|
76
|
+
* @example
|
|
77
|
+
* ```tsx
|
|
78
|
+
* const handleClick = (event) => {
|
|
79
|
+
* console.log('Document clicked!', event);
|
|
80
|
+
* };
|
|
81
|
+
*
|
|
82
|
+
* // Attach click event handler to document
|
|
83
|
+
* useClickAnywhere(handleClick);
|
|
84
|
+
* ```
|
|
85
|
+
*/
|
|
86
|
+
declare function useClickAnyWhere(handler: (event: MouseEvent) => void): void;
|
|
87
|
+
|
|
88
|
+
//#endregion
|
|
89
|
+
//#region src/useCopyToClipboard/useCopyToClipboard.d.ts
|
|
90
|
+
/**
|
|
91
|
+
* The copied text as `string` or `null` if nothing has been copied yet.
|
|
92
|
+
*/
|
|
93
|
+
type CopiedValue = string | null;
|
|
94
|
+
/**
|
|
95
|
+
* Function to copy text to the clipboard.
|
|
96
|
+
* @param text - The text to copy to the clipboard.
|
|
97
|
+
* @returns {Promise<boolean>} A promise that resolves to `true` if the text was copied successfully, or `false` otherwise.
|
|
98
|
+
*/
|
|
99
|
+
type CopyFn = (text: string) => Promise<boolean>;
|
|
100
|
+
/**
|
|
101
|
+
* Custom hook that copies text to the clipboard using the [`Clipboard API`](https://developer.mozilla.org/en-US/docs/Web/API/Clipboard_API).
|
|
102
|
+
* @returns {[CopiedValue, CopyFn]} An tuple containing the copied text and a function to copy text to the clipboard.
|
|
103
|
+
* @public
|
|
104
|
+
* @see [Documentation](https://usehooks-ts.com/react-hook/use-copy-to-clipboard)
|
|
105
|
+
* @example
|
|
106
|
+
* ```tsx
|
|
107
|
+
* const [copiedText, copyToClipboard] = useCopyToClipboard();
|
|
108
|
+
* const textToCopy = 'Hello, world!';
|
|
109
|
+
*
|
|
110
|
+
* // Attempt to copy text to the clipboard
|
|
111
|
+
* copyToClipboard(textToCopy)
|
|
112
|
+
* .then(success => {
|
|
113
|
+
* if (success) {
|
|
114
|
+
* console.log(`Text "${textToCopy}" copied to clipboard successfully.`);
|
|
115
|
+
* } else {
|
|
116
|
+
* console.error('Failed to copy text to clipboard.');
|
|
117
|
+
* }
|
|
118
|
+
* });
|
|
119
|
+
* ```
|
|
120
|
+
*/
|
|
121
|
+
declare function useCopyToClipboard(): [CopiedValue, CopyFn];
|
|
122
|
+
|
|
123
|
+
//#endregion
|
|
124
|
+
//#region src/useCountdown/useCountdown.d.ts
|
|
125
|
+
/** The countdown's options. */
|
|
126
|
+
type CountdownOptions = {
|
|
127
|
+
/** The countdown's starting number, initial value of the returned number. */
|
|
128
|
+
countStart: number;
|
|
129
|
+
/**
|
|
130
|
+
* The countdown's interval, in milliseconds.
|
|
131
|
+
* @default 1000
|
|
132
|
+
*/
|
|
133
|
+
intervalMs?: number;
|
|
134
|
+
/**
|
|
135
|
+
* True if the countdown is increment.
|
|
136
|
+
* @default false
|
|
137
|
+
*/
|
|
138
|
+
isIncrement?: boolean;
|
|
139
|
+
/**
|
|
140
|
+
* The countdown's stopping number. Pass `-Infinity` to decrease forever.
|
|
141
|
+
* @default 0
|
|
142
|
+
*/
|
|
143
|
+
countStop?: number;
|
|
144
|
+
};
|
|
145
|
+
/** The countdown's controllers. */
|
|
146
|
+
type CountdownControllers = {
|
|
147
|
+
/** Start the countdown. */
|
|
148
|
+
startCountdown: () => void;
|
|
149
|
+
/** Stop the countdown. */
|
|
150
|
+
stopCountdown: () => void;
|
|
151
|
+
/** Reset the countdown. */
|
|
152
|
+
resetCountdown: () => void;
|
|
153
|
+
};
|
|
154
|
+
/**
|
|
155
|
+
* Custom hook that manages countdown.
|
|
156
|
+
* @param {CountdownOptions} countdownOptions - The countdown's options.
|
|
157
|
+
* @returns {[number, CountdownControllers]} An array containing the countdown's count and its controllers.
|
|
158
|
+
* @public
|
|
159
|
+
* @see [Documentation](https://usehooks-ts.com/react-hook/use-countdown)
|
|
160
|
+
* @example
|
|
161
|
+
* ```tsx
|
|
162
|
+
* const [counter, { start, stop, reset }] = useCountdown({
|
|
163
|
+
* countStart: 10,
|
|
164
|
+
* intervalMs: 1000,
|
|
165
|
+
* isIncrement: false,
|
|
166
|
+
* });
|
|
167
|
+
* ```
|
|
168
|
+
*/
|
|
169
|
+
declare function useCountdown({
|
|
170
|
+
countStart,
|
|
171
|
+
countStop,
|
|
172
|
+
intervalMs,
|
|
173
|
+
isIncrement
|
|
174
|
+
}: CountdownOptions): [number, CountdownControllers];
|
|
175
|
+
|
|
176
|
+
//#endregion
|
|
177
|
+
//#region src/useCounter/useCounter.d.ts
|
|
178
|
+
/** The hook return type. */
|
|
179
|
+
type UseCounterReturn = {
|
|
180
|
+
/** The current count value. */
|
|
181
|
+
count: number;
|
|
182
|
+
/** Function to increment the counter by 1. */
|
|
183
|
+
increment: () => void;
|
|
184
|
+
/** Function to decrement the counter by 1. */
|
|
185
|
+
decrement: () => void;
|
|
186
|
+
/** Function to reset the counter to its initial value. */
|
|
187
|
+
reset: () => void;
|
|
188
|
+
/** Function to set a specific value to the counter. */
|
|
189
|
+
setCount: Dispatch<SetStateAction<number>>;
|
|
190
|
+
};
|
|
191
|
+
/**
|
|
192
|
+
* Custom hook that manages a counter with increment, decrement, reset, and setCount functionalities.
|
|
193
|
+
* @param {number} [initialValue] - The initial value for the counter.
|
|
194
|
+
* @returns {UseCounterReturn} An object containing the current count and functions to interact with the counter.
|
|
195
|
+
* @public
|
|
196
|
+
* @see [Documentation](https://usehooks-ts.com/react-hook/use-counter)
|
|
197
|
+
* @example
|
|
198
|
+
* ```tsx
|
|
199
|
+
* const { count, increment, decrement, reset, setCount } = useCounter(5);
|
|
200
|
+
* ```
|
|
201
|
+
*/
|
|
202
|
+
declare function useCounter(initialValue?: number): UseCounterReturn;
|
|
203
|
+
|
|
204
|
+
//#endregion
|
|
205
|
+
//#region src/useDarkMode/useDarkMode.d.ts
|
|
206
|
+
/** The hook options. */
|
|
207
|
+
type DarkModeOptions = {
|
|
208
|
+
/**
|
|
209
|
+
* The initial value of the dark mode.
|
|
210
|
+
* @default false
|
|
211
|
+
*/
|
|
212
|
+
defaultValue?: boolean;
|
|
213
|
+
/**
|
|
214
|
+
* The key to use in the local storage.
|
|
215
|
+
* @default 'usehooks-ts-dark-mode'
|
|
216
|
+
*/
|
|
217
|
+
localStorageKey?: string;
|
|
218
|
+
/**
|
|
219
|
+
* If `true` (default), the hook will initialize reading `localStorage`.
|
|
220
|
+
* In SSR, you should set it to `false`, returning the `defaultValue` or `false` initially.
|
|
221
|
+
* @default true
|
|
222
|
+
*/
|
|
223
|
+
initializeWithValue?: boolean;
|
|
224
|
+
};
|
|
225
|
+
/** The hook return type. */
|
|
226
|
+
type DarkModeReturn = {
|
|
227
|
+
/** The current state of the dark mode. */
|
|
228
|
+
isDarkMode: boolean;
|
|
229
|
+
/** Function to toggle the dark mode. */
|
|
230
|
+
toggle: () => void;
|
|
231
|
+
/** Function to enable the dark mode. */
|
|
232
|
+
enable: () => void;
|
|
233
|
+
/** Function to disable the dark mode. */
|
|
234
|
+
disable: () => void;
|
|
235
|
+
/** Function to set a specific value to the dark mode. */
|
|
236
|
+
set: (value: boolean) => void;
|
|
237
|
+
};
|
|
238
|
+
/**
|
|
239
|
+
* Custom hook that returns the current state of the dark mode.
|
|
240
|
+
* @param {?DarkModeOptions} [options] - The initial value of the dark mode, default `false`.
|
|
241
|
+
* @returns {DarkModeReturn} An object containing the dark mode's state and its controllers.
|
|
242
|
+
* @public
|
|
243
|
+
* @see [Documentation](https://usehooks-ts.com/react-hook/use-dark-mode)
|
|
244
|
+
* @example
|
|
245
|
+
* ```tsx
|
|
246
|
+
* const { isDarkMode, toggle, enable, disable, set } = useDarkMode({ defaultValue: true });
|
|
247
|
+
* ```
|
|
248
|
+
*/
|
|
249
|
+
declare function useDarkMode(options?: DarkModeOptions): DarkModeReturn;
|
|
250
|
+
|
|
251
|
+
//#endregion
|
|
252
|
+
//#region src/utils/debounce.d.ts
|
|
253
|
+
/** Options for controlling debounce behavior. */
|
|
254
|
+
interface DebounceOptions {
|
|
255
|
+
/** Invoke on the leading edge of the timeout. */
|
|
256
|
+
leading?: boolean;
|
|
257
|
+
/** Invoke on the trailing edge of the timeout. */
|
|
258
|
+
trailing?: boolean;
|
|
259
|
+
/** Maximum time to delay before invoking. */
|
|
260
|
+
maxWait?: number;
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
//#endregion
|
|
264
|
+
//#region src/useDebounceCallback/useDebounceCallback.d.ts
|
|
265
|
+
/** A debounced function with control methods. */
|
|
266
|
+
/** Functions to manage a debounced callback. */
|
|
267
|
+
type ControlFunctions = {
|
|
268
|
+
/** Cancels pending function invocations. */
|
|
269
|
+
cancel: () => void;
|
|
270
|
+
/** Immediately invokes pending function invocations. */
|
|
271
|
+
flush: () => void;
|
|
272
|
+
/**
|
|
273
|
+
* Checks if there are any pending function invocations.
|
|
274
|
+
* @returns `true` if there are pending invocations, otherwise `false`.
|
|
275
|
+
*/
|
|
276
|
+
isPending: () => boolean;
|
|
277
|
+
};
|
|
278
|
+
/**
|
|
279
|
+
* Represents the state and control functions of a debounced callback.
|
|
280
|
+
* Subsequent calls to the debounced function return the result of the last invocation.
|
|
281
|
+
* Note: If there are no previous invocations, the result will be undefined.
|
|
282
|
+
* Ensure proper handling in your code.
|
|
283
|
+
*/
|
|
284
|
+
type DebouncedState<T extends (...args: any) => ReturnType<T>> = ((...args: Parameters<T>) => ReturnType<T> | undefined) & ControlFunctions;
|
|
285
|
+
/**
|
|
286
|
+
* Custom hook that creates a debounced version of a callback function.
|
|
287
|
+
* @template T - Type of the original callback function.
|
|
288
|
+
* @param {T} func - The callback function to be debounced.
|
|
289
|
+
* @param {number} delay - The delay in milliseconds before the callback is invoked (default is `500` milliseconds).
|
|
290
|
+
* @param {DebounceOptions} [options] - Options to control the behavior of the debounced function.
|
|
291
|
+
* @returns {DebouncedState<T>} A debounced version of the original callback along with control functions.
|
|
292
|
+
* @public
|
|
293
|
+
* @see [Documentation](https://usehooks-ts.com/react-hook/use-debounce-callback)
|
|
294
|
+
* @example
|
|
295
|
+
* ```tsx
|
|
296
|
+
* const debouncedCallback = useDebounceCallback(
|
|
297
|
+
* (searchTerm) => {
|
|
298
|
+
* // Perform search after user stops typing for 500 milliseconds
|
|
299
|
+
* searchApi(searchTerm);
|
|
300
|
+
* },
|
|
301
|
+
* 500
|
|
302
|
+
* );
|
|
303
|
+
*
|
|
304
|
+
* // Later in the component
|
|
305
|
+
* debouncedCallback('react hooks'); // Will invoke the callback after 500 milliseconds of inactivity.
|
|
306
|
+
* ```
|
|
307
|
+
*/
|
|
308
|
+
declare function useDebounceCallback<T extends (...args: any) => ReturnType<T>>(func: T, delay?: number, options?: DebounceOptions): DebouncedState<T>;
|
|
309
|
+
|
|
310
|
+
//#endregion
|
|
311
|
+
//#region src/useDebounceValue/useDebounceValue.d.ts
|
|
312
|
+
/**
|
|
313
|
+
* Hook options.
|
|
314
|
+
* @template T - The type of the value.
|
|
315
|
+
*/
|
|
316
|
+
type UseDebounceValueOptions<T> = {
|
|
317
|
+
/**
|
|
318
|
+
* Determines whether the function should be invoked on the leading edge of the timeout.
|
|
319
|
+
* @default false
|
|
320
|
+
*/
|
|
321
|
+
leading?: boolean;
|
|
322
|
+
/**
|
|
323
|
+
* Determines whether the function should be invoked on the trailing edge of the timeout.
|
|
324
|
+
* @default false
|
|
325
|
+
*/
|
|
326
|
+
trailing?: boolean;
|
|
327
|
+
/**
|
|
328
|
+
* The maximum time the specified function is allowed to be delayed before it is invoked.
|
|
329
|
+
*/
|
|
330
|
+
maxWait?: number;
|
|
331
|
+
/** A function to determine if the value has changed. Defaults to a function that checks if the value is strictly equal to the previous value. */
|
|
332
|
+
equalityFn?: (left: T, right: T) => boolean;
|
|
333
|
+
};
|
|
334
|
+
/**
|
|
335
|
+
* Custom hook that returns a debounced version of the provided value, along with a function to update it.
|
|
336
|
+
* @template T - The type of the value.
|
|
337
|
+
* @param {T | (() => T)} initialValue - The value to be debounced.
|
|
338
|
+
* @param {number} delay - The delay in milliseconds before the value is updated (default is 500ms).
|
|
339
|
+
* @param {object} [options] - Optional configurations for the debouncing behavior.
|
|
340
|
+
* @returns {[T, DebouncedState<(value: T) => void>]} An array containing the debounced value and the function to update it.
|
|
341
|
+
* @public
|
|
342
|
+
* @see [Documentation](https://usehooks-ts.com/react-hook/use-debounce-value)
|
|
343
|
+
* @example
|
|
344
|
+
* ```tsx
|
|
345
|
+
* const [debouncedValue, updateDebouncedValue] = useDebounceValue(inputValue, 500, { leading: true });
|
|
346
|
+
* ```
|
|
347
|
+
*/
|
|
348
|
+
declare function useDebounceValue<T>(initialValue: T | (() => T), delay: number, options?: UseDebounceValueOptions<T>): [T, DebouncedState<(value: T) => void>];
|
|
349
|
+
|
|
350
|
+
//#endregion
|
|
351
|
+
//#region src/useDisclosure/useDisclosure.d.ts
|
|
352
|
+
/**
|
|
353
|
+
* Options for the useDisclosure hook.
|
|
354
|
+
*/
|
|
355
|
+
type UseDisclosureOptions = {
|
|
356
|
+
/** Callback fired when disclosure opens. */
|
|
357
|
+
onOpen?: () => void;
|
|
358
|
+
/** Callback fired when disclosure closes. */
|
|
359
|
+
onClose?: () => void;
|
|
360
|
+
};
|
|
361
|
+
/**
|
|
362
|
+
* Represents the actions returned by useDisclosure hook.
|
|
363
|
+
*/
|
|
364
|
+
type UseDisclosureActions = {
|
|
365
|
+
/** Open the disclosure. */
|
|
366
|
+
open: () => void;
|
|
367
|
+
/** Close the disclosure. */
|
|
368
|
+
close: () => void;
|
|
369
|
+
/** Toggle the disclosure state. */
|
|
370
|
+
toggle: () => void;
|
|
371
|
+
};
|
|
372
|
+
/**
|
|
373
|
+
* Represents the return type of the `useDisclosure` hook.
|
|
374
|
+
*/
|
|
375
|
+
type UseDisclosureReturn = [boolean, UseDisclosureActions];
|
|
376
|
+
/**
|
|
377
|
+
* Custom hook for managing boolean disclosure state (modals, popovers, drawers, etc.).
|
|
378
|
+
* @param {boolean} [initialState=false] - The initial open state.
|
|
379
|
+
* @param {UseDisclosureOptions} [options] - Optional callbacks for open/close events.
|
|
380
|
+
* @returns {UseDisclosureReturn} A tuple containing the open state and control actions.
|
|
381
|
+
* @public
|
|
382
|
+
* @see [Documentation](https://usehooks-ts.com/react-hook/use-disclosure)
|
|
383
|
+
* @example
|
|
384
|
+
* ```tsx
|
|
385
|
+
* const [opened, { open, close, toggle }] = useDisclosure(false, {
|
|
386
|
+
* onOpen: () => console.log('Opened'),
|
|
387
|
+
* onClose: () => console.log('Closed'),
|
|
388
|
+
* });
|
|
389
|
+
*
|
|
390
|
+
* return (
|
|
391
|
+
* <>
|
|
392
|
+
* <button onClick={open}>Open Modal</button>
|
|
393
|
+
* <Modal opened={opened} onClose={close}>
|
|
394
|
+
* <button onClick={close}>Close</button>
|
|
395
|
+
* </Modal>
|
|
396
|
+
* </>
|
|
397
|
+
* );
|
|
398
|
+
* ```
|
|
399
|
+
*/
|
|
400
|
+
declare function useDisclosure(initialState?: boolean, options?: UseDisclosureOptions): UseDisclosureReturn;
|
|
401
|
+
|
|
402
|
+
//#endregion
|
|
403
|
+
//#region src/useDocumentTitle/useDocumentTitle.d.ts
|
|
404
|
+
/** Hook options. */
|
|
405
|
+
type UseDocumentTitleOptions = {
|
|
406
|
+
/** Whether to keep the title after unmounting the component (default is `true`). */
|
|
407
|
+
preserveTitleOnUnmount?: boolean;
|
|
408
|
+
};
|
|
409
|
+
/**
|
|
410
|
+
* Custom hook that sets the document title.
|
|
411
|
+
* @param {string} title - The title to set.
|
|
412
|
+
* @param {?UseDocumentTitleOptions} [options] - The options.
|
|
413
|
+
* @public
|
|
414
|
+
* @see [Documentation](https://usehooks-ts.com/react-hook/use-document-title)
|
|
415
|
+
* @example
|
|
416
|
+
* ```tsx
|
|
417
|
+
* useDocumentTitle('My new title');
|
|
418
|
+
* ```
|
|
419
|
+
*/
|
|
420
|
+
declare function useDocumentTitle(title: string, options?: UseDocumentTitleOptions): void;
|
|
421
|
+
|
|
422
|
+
//#endregion
|
|
423
|
+
//#region src/useEventCallback/useEventCallback.d.ts
|
|
424
|
+
/**
|
|
425
|
+
* Custom hook that creates a memoized event callback.
|
|
426
|
+
* @template Args - An array of argument types for the event callback.
|
|
427
|
+
* @template R - The return type of the event callback.
|
|
428
|
+
* @param {(...args: Args) => R} fn - The callback function.
|
|
429
|
+
* @returns {(...args: Args) => R} A memoized event callback function.
|
|
430
|
+
* @public
|
|
431
|
+
* @see [Documentation](https://usehooks-ts.com/react-hook/use-event-callback)
|
|
432
|
+
* @example
|
|
433
|
+
* ```tsx
|
|
434
|
+
* const handleClick = useEventCallback((event) => {
|
|
435
|
+
* // Handle the event here
|
|
436
|
+
* });
|
|
437
|
+
* ```
|
|
438
|
+
*/
|
|
439
|
+
declare function useEventCallback<Args extends unknown[], R>(fn: (...args: Args) => R): (...args: Args) => R;
|
|
440
|
+
declare function useEventCallback<Args extends unknown[], R>(fn: ((...args: Args) => R) | undefined): ((...args: Args) => R) | undefined;
|
|
441
|
+
|
|
442
|
+
//#endregion
|
|
443
|
+
//#region src/useEventListener/useEventListener.d.ts
|
|
444
|
+
declare function useEventListener<K extends keyof MediaQueryListEventMap>(eventName: K, handler: (event: MediaQueryListEventMap[K]) => void, element: RefObject<MediaQueryList | null>, options?: boolean | AddEventListenerOptions): void;
|
|
445
|
+
declare function useEventListener<K extends keyof WindowEventMap>(eventName: K, handler: (event: WindowEventMap[K]) => void, element?: undefined, options?: boolean | AddEventListenerOptions): void;
|
|
446
|
+
declare function useEventListener<K extends keyof HTMLElementEventMap & keyof SVGElementEventMap, T extends Element = (K extends keyof HTMLElementEventMap ? HTMLDivElement : SVGElement)>(eventName: K, handler: ((event: HTMLElementEventMap[K]) => void) | ((event: SVGElementEventMap[K]) => void), element: RefObject<T | null>, options?: boolean | AddEventListenerOptions): void;
|
|
447
|
+
declare function useEventListener<K extends keyof DocumentEventMap>(eventName: K, handler: (event: DocumentEventMap[K]) => void, element: RefObject<Document | null>, options?: boolean | AddEventListenerOptions): void;
|
|
448
|
+
|
|
449
|
+
//#endregion
|
|
450
|
+
//#region src/useGeolocation/useGeolocation.d.ts
|
|
451
|
+
/**
|
|
452
|
+
* Represents the state of geolocation.
|
|
453
|
+
*/
|
|
454
|
+
type UseGeolocationState = {
|
|
455
|
+
/** The latitude coordinate. */
|
|
456
|
+
latitude: number | undefined;
|
|
457
|
+
/** The longitude coordinate. */
|
|
458
|
+
longitude: number | undefined;
|
|
459
|
+
/** The accuracy of the location in meters. */
|
|
460
|
+
accuracy: number | undefined;
|
|
461
|
+
/** The altitude in meters. */
|
|
462
|
+
altitude: number | null | undefined;
|
|
463
|
+
/** The accuracy of the altitude in meters. */
|
|
464
|
+
altitudeAccuracy: number | null | undefined;
|
|
465
|
+
/** The heading in degrees (0-360). */
|
|
466
|
+
heading: number | null | undefined;
|
|
467
|
+
/** The speed in meters per second. */
|
|
468
|
+
speed: number | null | undefined;
|
|
469
|
+
/** The timestamp of the position. */
|
|
470
|
+
timestamp: number | undefined;
|
|
471
|
+
/** Whether the geolocation is loading. */
|
|
472
|
+
loading: boolean;
|
|
473
|
+
/** The error object if geolocation failed. */
|
|
474
|
+
error: GeolocationPositionError | Error | undefined;
|
|
475
|
+
};
|
|
476
|
+
/**
|
|
477
|
+
* Options for the useGeolocation hook.
|
|
478
|
+
* Extends the standard PositionOptions with an enabled flag.
|
|
479
|
+
*/
|
|
480
|
+
type UseGeolocationOptions = {
|
|
481
|
+
/** Whether to enable high accuracy mode. */
|
|
482
|
+
enableHighAccuracy?: boolean;
|
|
483
|
+
/** The maximum time in milliseconds allowed to get the position. */
|
|
484
|
+
timeout?: number;
|
|
485
|
+
/** The maximum age in milliseconds of a cached position. */
|
|
486
|
+
maximumAge?: number;
|
|
487
|
+
/** Whether to enable geolocation. Set to false to prevent fetching. */
|
|
488
|
+
enabled?: boolean;
|
|
489
|
+
};
|
|
490
|
+
/**
|
|
491
|
+
* Custom hook that provides access to the browser's geolocation API.
|
|
492
|
+
* @param {UseGeolocationOptions} [options] - Options for geolocation and hook behavior.
|
|
493
|
+
* @returns {UseGeolocationState} The current geolocation state.
|
|
494
|
+
* @public
|
|
495
|
+
* @see [Documentation](https://usehooks-ts.com/react-hook/use-geolocation)
|
|
496
|
+
* @example
|
|
497
|
+
* ```tsx
|
|
498
|
+
* const { latitude, longitude, loading, error } = useGeolocation({
|
|
499
|
+
* enableHighAccuracy: true,
|
|
500
|
+
* timeout: 5000,
|
|
501
|
+
* });
|
|
502
|
+
*
|
|
503
|
+
* if (loading) return <div>Loading location...</div>;
|
|
504
|
+
* if (error) return <div>Error: {error.message}</div>;
|
|
505
|
+
* return <div>Location: {latitude}, {longitude}</div>;
|
|
506
|
+
* ```
|
|
507
|
+
*/
|
|
508
|
+
declare function useGeolocation(options?: UseGeolocationOptions): UseGeolocationState;
|
|
509
|
+
|
|
510
|
+
//#endregion
|
|
511
|
+
//#region src/useHover/useHover.d.ts
|
|
512
|
+
/**
|
|
513
|
+
* Custom hook that tracks whether a DOM element is being hovered over.
|
|
514
|
+
* @template T - The type of the DOM element. Defaults to `HTMLElement`.
|
|
515
|
+
* @param {RefObject<T>} elementRef - The ref object for the DOM element to track.
|
|
516
|
+
* @returns {boolean} A boolean value indicating whether the element is being hovered over.
|
|
517
|
+
* @public
|
|
518
|
+
* @see [Documentation](https://usehooks-ts.com/react-hook/use-hover)
|
|
519
|
+
* @example
|
|
520
|
+
* ```tsx
|
|
521
|
+
* const buttonRef = useRef<HTMLButtonElement>(null);
|
|
522
|
+
* const isHovered = useHover(buttonRef);
|
|
523
|
+
* // Access the isHovered variable to determine if the button is being hovered over.
|
|
524
|
+
* ```
|
|
525
|
+
*/
|
|
526
|
+
declare function useHover<T extends HTMLElement = HTMLElement>(elementRef: RefObject<T | null>): boolean;
|
|
527
|
+
|
|
528
|
+
//#endregion
|
|
529
|
+
//#region src/useIdle/useIdle.d.ts
|
|
530
|
+
/**
|
|
531
|
+
* Options for the useIdle hook.
|
|
532
|
+
*/
|
|
533
|
+
type UseIdleOptions = {
|
|
534
|
+
/** Events that should reset the idle timer. */
|
|
535
|
+
events?: (keyof WindowEventMap)[];
|
|
536
|
+
/** Whether to start in idle state. */
|
|
537
|
+
initialIdle?: boolean;
|
|
538
|
+
};
|
|
539
|
+
/**
|
|
540
|
+
* Represents the state returned by useIdle hook.
|
|
541
|
+
*/
|
|
542
|
+
type IdleState = {
|
|
543
|
+
/** Whether the user is currently idle. */
|
|
544
|
+
idle: boolean;
|
|
545
|
+
/** The timestamp of the last user activity. */
|
|
546
|
+
lastActive: number;
|
|
547
|
+
};
|
|
548
|
+
/**
|
|
549
|
+
* Custom hook that tracks whether the user is idle (no activity for a specified time).
|
|
550
|
+
* @param {number} timeout - The time in milliseconds of inactivity before considering the user idle.
|
|
551
|
+
* @param {UseIdleOptions} [options] - Options for customizing the hook behavior.
|
|
552
|
+
* @returns {IdleState} The current idle state and last activity timestamp.
|
|
553
|
+
* @public
|
|
554
|
+
* @see [Documentation](https://usehooks-ts.com/react-hook/use-idle)
|
|
555
|
+
* @example
|
|
556
|
+
* ```tsx
|
|
557
|
+
* const { idle, lastActive } = useIdle(5000);
|
|
558
|
+
*
|
|
559
|
+
* return (
|
|
560
|
+
* <div>
|
|
561
|
+
* <p>{idle ? 'User is idle' : 'User is active'}</p>
|
|
562
|
+
* <p>Last active: {new Date(lastActive).toLocaleString()}</p>
|
|
563
|
+
* </div>
|
|
564
|
+
* );
|
|
565
|
+
* ```
|
|
566
|
+
*/
|
|
567
|
+
declare function useIdle(timeout: number, options?: UseIdleOptions): IdleState;
|
|
568
|
+
|
|
569
|
+
//#endregion
|
|
570
|
+
//#region src/useIntersectionObserver/useIntersectionObserver.d.ts
|
|
571
|
+
/** The hook internal state. */
|
|
572
|
+
type UseIntersectionObserverState = {
|
|
573
|
+
/** A boolean indicating if the element is intersecting. */
|
|
574
|
+
isIntersecting: boolean;
|
|
575
|
+
/** The intersection observer entry. */
|
|
576
|
+
entry?: IntersectionObserverEntry;
|
|
577
|
+
};
|
|
578
|
+
/** Represents the options for configuring the Intersection Observer. */
|
|
579
|
+
type UseIntersectionObserverOptions = {
|
|
580
|
+
/**
|
|
581
|
+
* The element that is used as the viewport for checking visibility of the target.
|
|
582
|
+
* @default null
|
|
583
|
+
*/
|
|
584
|
+
root?: Element | Document | null;
|
|
585
|
+
/**
|
|
586
|
+
* A margin around the root.
|
|
587
|
+
* @default '0%'
|
|
588
|
+
*/
|
|
589
|
+
rootMargin?: string;
|
|
590
|
+
/**
|
|
591
|
+
* A threshold indicating the percentage of the target's visibility needed to trigger the callback.
|
|
592
|
+
* @default 0
|
|
593
|
+
*/
|
|
594
|
+
threshold?: number | number[];
|
|
595
|
+
/**
|
|
596
|
+
* If true, freezes the intersection state once the element becomes visible.
|
|
597
|
+
* @default false
|
|
598
|
+
*/
|
|
599
|
+
freezeOnceVisible?: boolean;
|
|
600
|
+
/**
|
|
601
|
+
* A callback function to be invoked when the intersection state changes.
|
|
602
|
+
* @param {boolean} isIntersecting - A boolean indicating if the element is intersecting.
|
|
603
|
+
* @param {IntersectionObserverEntry} entry - The intersection observer Entry.
|
|
604
|
+
* @default undefined
|
|
605
|
+
*/
|
|
606
|
+
onChange?: (isIntersecting: boolean, entry: IntersectionObserverEntry) => void;
|
|
607
|
+
/**
|
|
608
|
+
* The initial state of the intersection.
|
|
609
|
+
* @default false
|
|
610
|
+
*/
|
|
611
|
+
initialIsIntersecting?: boolean;
|
|
612
|
+
};
|
|
613
|
+
/**
|
|
614
|
+
* The return type of the useIntersectionObserver hook.
|
|
615
|
+
*
|
|
616
|
+
* Supports both tuple and object destructing.
|
|
617
|
+
* @param {(node: Element | null) => void} ref - The ref callback function.
|
|
618
|
+
* @param {boolean} isIntersecting - A boolean indicating if the element is intersecting.
|
|
619
|
+
* @param {IntersectionObserverEntry | undefined} entry - The intersection observer Entry.
|
|
620
|
+
*/
|
|
621
|
+
type IntersectionReturn = [(node?: Element | null) => void, boolean, IntersectionObserverEntry | undefined] & {
|
|
622
|
+
ref: (node?: Element | null) => void;
|
|
623
|
+
isIntersecting: boolean;
|
|
624
|
+
entry?: IntersectionObserverEntry;
|
|
625
|
+
};
|
|
626
|
+
/**
|
|
627
|
+
* Custom hook that tracks the intersection of a DOM element with its containing element or the viewport using the [`Intersection Observer API`](https://developer.mozilla.org/en-US/docs/Web/API/Intersection_Observer_API).
|
|
628
|
+
* @param {UseIntersectionObserverOptions} options - The options for the Intersection Observer.
|
|
629
|
+
* @returns {IntersectionReturn} The ref callback, a boolean indicating if the element is intersecting, and the intersection observer entry.
|
|
630
|
+
* @public
|
|
631
|
+
* @see [Documentation](https://usehooks-ts.com/react-hook/use-intersection-observer)
|
|
632
|
+
* @example
|
|
633
|
+
* ```tsx
|
|
634
|
+
* // Example 1
|
|
635
|
+
* const [ref, isIntersecting, entry] = useIntersectionObserver({ threshold: 0.5 });
|
|
636
|
+
* ```
|
|
637
|
+
*
|
|
638
|
+
* ```tsx
|
|
639
|
+
* // Example 2
|
|
640
|
+
* const { ref, isIntersecting, entry } = useIntersectionObserver({ threshold: 0.5 });
|
|
641
|
+
* ```
|
|
642
|
+
*/
|
|
643
|
+
declare function useIntersectionObserver({
|
|
644
|
+
threshold,
|
|
645
|
+
root,
|
|
646
|
+
rootMargin,
|
|
647
|
+
freezeOnceVisible,
|
|
648
|
+
initialIsIntersecting,
|
|
649
|
+
onChange
|
|
650
|
+
}?: UseIntersectionObserverOptions): IntersectionReturn;
|
|
651
|
+
|
|
652
|
+
//#endregion
|
|
653
|
+
//#region src/useInterval/useInterval.d.ts
|
|
654
|
+
/**
|
|
655
|
+
* Custom hook that creates an interval that invokes a callback function at a specified delay using the [`setInterval API`](https://developer.mozilla.org/en-US/docs/Web/API/WindowOrWorkerGlobalScope/setInterval).
|
|
656
|
+
* @param {() => void} callback - The function to be invoked at each interval.
|
|
657
|
+
* @param {number | null} delay - The time, in milliseconds, between each invocation of the callback. Use `null` to clear the interval.
|
|
658
|
+
* @public
|
|
659
|
+
* @see [Documentation](https://usehooks-ts.com/react-hook/use-interval)
|
|
660
|
+
* @example
|
|
661
|
+
* ```tsx
|
|
662
|
+
* const handleInterval = () => {
|
|
663
|
+
* // Code to be executed at each interval
|
|
664
|
+
* };
|
|
665
|
+
* useInterval(handleInterval, 1000);
|
|
666
|
+
* ```
|
|
667
|
+
*/
|
|
668
|
+
declare function useInterval(callback: () => void, delay: number | null): void;
|
|
669
|
+
|
|
670
|
+
//#endregion
|
|
671
|
+
//#region src/useIsClient/useIsClient.d.ts
|
|
672
|
+
/**
|
|
673
|
+
* Custom hook that determines if the code is running on the client side (in the browser).
|
|
674
|
+
* @returns {boolean} A boolean value indicating whether the code is running on the client side.
|
|
675
|
+
* @public
|
|
676
|
+
* @see [Documentation](https://usehooks-ts.com/react-hook/use-is-client)
|
|
677
|
+
* @example
|
|
678
|
+
* ```tsx
|
|
679
|
+
* const isClient = useIsClient();
|
|
680
|
+
* // Use isClient to conditionally render or execute code specific to the client side.
|
|
681
|
+
* ```
|
|
682
|
+
*/
|
|
683
|
+
declare function useIsClient(): boolean;
|
|
684
|
+
|
|
685
|
+
//#endregion
|
|
686
|
+
//#region src/useIsMounted/useIsMounted.d.ts
|
|
687
|
+
/**
|
|
688
|
+
* Custom hook that determines if the component is currently mounted.
|
|
689
|
+
* @returns {() => boolean} A function that returns a boolean value indicating whether the component is mounted.
|
|
690
|
+
* @public
|
|
691
|
+
* @see [Documentation](https://usehooks-ts.com/react-hook/use-is-mounted)
|
|
692
|
+
* @example
|
|
693
|
+
* ```tsx
|
|
694
|
+
* const isComponentMounted = useIsMounted();
|
|
695
|
+
* // Use isComponentMounted() to check if the component is currently mounted before performing certain actions.
|
|
696
|
+
* ```
|
|
697
|
+
*/
|
|
698
|
+
declare function useIsMounted(): () => boolean;
|
|
699
|
+
|
|
700
|
+
//#endregion
|
|
701
|
+
//#region src/useIsomorphicLayoutEffect/useIsomorphicLayoutEffect.d.ts
|
|
702
|
+
/**
|
|
703
|
+
* Custom hook that uses either `useLayoutEffect` or `useEffect` based on the environment (client-side or server-side).
|
|
704
|
+
* @param {Function} effect - The effect function to be executed.
|
|
705
|
+
* @param {Array<any>} [dependencies] - An array of dependencies for the effect (optional).
|
|
706
|
+
* @public
|
|
707
|
+
* @see [Documentation](https://usehooks-ts.com/react-hook/use-isomorphic-layout-effect)
|
|
708
|
+
* @example
|
|
709
|
+
* ```tsx
|
|
710
|
+
* useIsomorphicLayoutEffect(() => {
|
|
711
|
+
* // Code to be executed during the layout phase on the client side
|
|
712
|
+
* }, [dependency1, dependency2]);
|
|
713
|
+
* ```
|
|
714
|
+
*/
|
|
715
|
+
declare const useIsomorphicLayoutEffect: typeof useEffect;
|
|
716
|
+
|
|
717
|
+
//#endregion
|
|
718
|
+
//#region src/useList/useList.d.ts
|
|
719
|
+
/**
|
|
720
|
+
* Represents the actions available to interact with the list state.
|
|
721
|
+
* @template T - The type of elements in the list.
|
|
722
|
+
*/
|
|
723
|
+
type UseListActions<T> = {
|
|
724
|
+
/** Set a new list. */
|
|
725
|
+
set: (list: T[]) => void;
|
|
726
|
+
/** Add value(s) to the end of the list. */
|
|
727
|
+
push: (...values: T[]) => void;
|
|
728
|
+
/** Update value at a specific index. */
|
|
729
|
+
updateAt: (index: number, value: T) => void;
|
|
730
|
+
/** Insert value at a specific index. */
|
|
731
|
+
insertAt: (index: number, value: T) => void;
|
|
732
|
+
/** Remove value at a specific index. */
|
|
733
|
+
removeAt: (index: number) => void;
|
|
734
|
+
/** Clear all values from the list. */
|
|
735
|
+
clear: () => void;
|
|
736
|
+
/** Reset the list to its initial state. */
|
|
737
|
+
reset: () => void;
|
|
738
|
+
};
|
|
739
|
+
/**
|
|
740
|
+
* Represents the return type of the `useList` hook.
|
|
741
|
+
* @template T - The type of elements in the list.
|
|
742
|
+
*/
|
|
743
|
+
type UseListReturn<T> = [T[], UseListActions<T>];
|
|
744
|
+
/**
|
|
745
|
+
* Custom hook that manages a list state with setter actions.
|
|
746
|
+
* @template T - The type of elements in the list.
|
|
747
|
+
* @param {T[]} [initialValue] - The initial array of values for the list (optional).
|
|
748
|
+
* @returns {UseListReturn<T>} A tuple containing the list state and actions to interact with the list.
|
|
749
|
+
* @public
|
|
750
|
+
* @see [Documentation](https://usehooks-ts.com/react-hook/use-list)
|
|
751
|
+
* @example
|
|
752
|
+
* ```tsx
|
|
753
|
+
* const [list, listActions] = useList<number>([1, 2, 3]);
|
|
754
|
+
* // Access the `list` array and use `listActions` to push, updateAt, removeAt, or reset values.
|
|
755
|
+
* ```
|
|
756
|
+
*/
|
|
757
|
+
declare function useList<T>(initialValue?: T[]): UseListReturn<T>;
|
|
758
|
+
|
|
759
|
+
//#endregion
|
|
760
|
+
//#region src/useLocalStorage/useLocalStorage.d.ts
|
|
761
|
+
declare global {
|
|
762
|
+
interface WindowEventMap {
|
|
763
|
+
'local-storage': CustomEvent;
|
|
764
|
+
}
|
|
765
|
+
}
|
|
766
|
+
/**
|
|
767
|
+
* Options for customizing the behavior of serialization and deserialization.
|
|
768
|
+
* @template T - The type of the state to be stored in local storage.
|
|
769
|
+
*/
|
|
770
|
+
type UseLocalStorageOptions<T> = {
|
|
771
|
+
/** A function to serialize the value before storing it. */
|
|
772
|
+
serializer?: (value: T) => string;
|
|
773
|
+
/** A function to deserialize the stored value. */
|
|
774
|
+
deserializer?: (value: string) => T;
|
|
775
|
+
/**
|
|
776
|
+
* If `true` (default), the hook will initialize reading the local storage. In SSR, you should set it to `false`, returning the initial value initially.
|
|
777
|
+
* @default true
|
|
778
|
+
*/
|
|
779
|
+
initializeWithValue?: boolean;
|
|
780
|
+
};
|
|
781
|
+
/**
|
|
782
|
+
* Custom hook that uses the [`localStorage API`](https://developer.mozilla.org/en-US/docs/Web/API/Window/localStorage) to persist state across page reloads.
|
|
783
|
+
* @template T - The type of the state to be stored in local storage.
|
|
784
|
+
* @param {string} key - The key under which the value will be stored in local storage.
|
|
785
|
+
* @param {T | (() => T)} initialValue - The initial value of the state or a function that returns the initial value.
|
|
786
|
+
* @param {UseLocalStorageOptions<T>} [options] - Options for customizing the behavior of serialization and deserialization (optional).
|
|
787
|
+
* @returns {[T, Dispatch<SetStateAction<T>>, () => void]} A tuple containing the stored value, a function to set the value and a function to remove the key from storage.
|
|
788
|
+
* @public
|
|
789
|
+
* @see [Documentation](https://usehooks-ts.com/react-hook/use-local-storage)
|
|
790
|
+
* @example
|
|
791
|
+
* ```tsx
|
|
792
|
+
* const [count, setCount, removeCount] = useLocalStorage('count', 0);
|
|
793
|
+
* // Access the `count` value, the `setCount` function to update it and `removeCount` function to remove the key from storage.
|
|
794
|
+
* ```
|
|
795
|
+
*/
|
|
796
|
+
declare function useLocalStorage<T>(key: string, initialValue: T | (() => T), options?: UseLocalStorageOptions<T>): [T, Dispatch<SetStateAction<T>>, () => void];
|
|
797
|
+
|
|
798
|
+
//#endregion
|
|
799
|
+
//#region src/useMap/useMap.d.ts
|
|
800
|
+
/**
|
|
801
|
+
* Represents the type for either a Map or an array of key-value pairs.
|
|
802
|
+
* @template K - The type of keys in the map.
|
|
803
|
+
* @template V - The type of values in the map.
|
|
804
|
+
*/
|
|
805
|
+
type MapOrEntries<K, V> = Map<K, V> | [K, V][];
|
|
806
|
+
/**
|
|
807
|
+
* Represents the actions available to interact with the map state.
|
|
808
|
+
* @template K - The type of keys in the map.
|
|
809
|
+
* @template V - The type of values in the map.
|
|
810
|
+
*/
|
|
811
|
+
type UseMapActions<K, V> = {
|
|
812
|
+
/** Set a key-value pair in the map. */
|
|
813
|
+
set: (key: K, value: V) => void;
|
|
814
|
+
/** Set all key-value pairs in the map. */
|
|
815
|
+
setAll: (entries: MapOrEntries<K, V>) => void;
|
|
816
|
+
/** Remove a key-value pair from the map. */
|
|
817
|
+
remove: (key: K) => void;
|
|
818
|
+
/** Reset the map to an empty state. */
|
|
819
|
+
reset: Map<K, V>['clear'];
|
|
820
|
+
};
|
|
821
|
+
/**
|
|
822
|
+
* Represents the return type of the `useMap` hook.
|
|
823
|
+
* We hide some setters from the returned map to disable autocompletion.
|
|
824
|
+
* @template K - The type of keys in the map.
|
|
825
|
+
* @template V - The type of values in the map.
|
|
826
|
+
*/
|
|
827
|
+
type UseMapReturn<K, V> = [Omit<Map<K, V>, 'set' | 'clear' | 'delete'>, UseMapActions<K, V>];
|
|
828
|
+
/**
|
|
829
|
+
* Custom hook that manages a key-value [`Map`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map) state with setter actions.
|
|
830
|
+
* @template K - The type of keys in the map.
|
|
831
|
+
* @template V - The type of values in the map.
|
|
832
|
+
* @param {MapOrEntries<K, V>} [initialState] - The initial state of the map as a Map or an array of key-value pairs (optional).
|
|
833
|
+
* @returns {UseMapReturn<K, V>} A tuple containing the map state and actions to interact with the map.
|
|
834
|
+
* @public
|
|
835
|
+
* @see [Documentation](https://usehooks-ts.com/react-hook/use-map)
|
|
836
|
+
* @example
|
|
837
|
+
* ```tsx
|
|
838
|
+
* const [map, mapActions] = useMap();
|
|
839
|
+
* // Access the `map` state and use `mapActions` to set, remove, or reset entries.
|
|
840
|
+
* ```
|
|
841
|
+
*/
|
|
842
|
+
declare function useMap<K, V>(initialState?: MapOrEntries<K, V>): UseMapReturn<K, V>;
|
|
843
|
+
|
|
844
|
+
//#endregion
|
|
845
|
+
//#region src/useMediaQuery/useMediaQuery.d.ts
|
|
846
|
+
/** Hook options. */
|
|
847
|
+
type UseMediaQueryOptions = {
|
|
848
|
+
/**
|
|
849
|
+
* The default value to return if the hook is being run on the server.
|
|
850
|
+
* @default false
|
|
851
|
+
*/
|
|
852
|
+
defaultValue?: boolean;
|
|
853
|
+
/**
|
|
854
|
+
* If `true` (default), the hook will initialize reading the media query. In SSR, you should set it to `false`, returning `options.defaultValue` or `false` initially.
|
|
855
|
+
* @default true
|
|
856
|
+
*/
|
|
857
|
+
initializeWithValue?: boolean;
|
|
858
|
+
};
|
|
859
|
+
/**
|
|
860
|
+
* Custom hook that tracks the state of a media query using the [`Match Media API`](https://developer.mozilla.org/en-US/docs/Web/API/Window/matchMedia).
|
|
861
|
+
* @param {string} query - The media query to track.
|
|
862
|
+
* @param {?UseMediaQueryOptions} [options] - The options for customizing the behavior of the hook (optional).
|
|
863
|
+
* @returns {boolean} The current state of the media query (true if the query matches, false otherwise).
|
|
864
|
+
* @public
|
|
865
|
+
* @see [Documentation](https://usehooks-ts.com/react-hook/use-media-query)
|
|
866
|
+
* @example
|
|
867
|
+
* ```tsx
|
|
868
|
+
* const isSmallScreen = useMediaQuery('(max-width: 600px)');
|
|
869
|
+
* // Use `isSmallScreen` to conditionally apply styles or logic based on the screen size.
|
|
870
|
+
* ```
|
|
871
|
+
*/
|
|
872
|
+
declare function useMediaQuery(query: string, {
|
|
873
|
+
defaultValue,
|
|
874
|
+
initializeWithValue
|
|
875
|
+
}?: UseMediaQueryOptions): boolean;
|
|
876
|
+
|
|
877
|
+
//#endregion
|
|
878
|
+
//#region src/useMemoizedFn/useMemoizedFn.d.ts
|
|
879
|
+
/**
|
|
880
|
+
* Custom hook that returns a memoized version of a function that never changes reference.
|
|
881
|
+
* The returned function will always call the latest version of the callback, but its
|
|
882
|
+
* identity (reference) will remain stable across renders.
|
|
883
|
+
*
|
|
884
|
+
* This is useful when you need to pass a callback to a dependency array or child component
|
|
885
|
+
* without causing unnecessary re-renders.
|
|
886
|
+
*
|
|
887
|
+
* @template T - The type of the function being memoized.
|
|
888
|
+
* @param {T} fn - The function to memoize.
|
|
889
|
+
* @returns {T} A memoized function with stable reference.
|
|
890
|
+
* @public
|
|
891
|
+
* @see [Documentation](https://usehooks-ts.com/react-hook/use-memoized-fn)
|
|
892
|
+
* @example
|
|
893
|
+
* ```tsx
|
|
894
|
+
* const stableCallback = useMemoizedFn((value) => {
|
|
895
|
+
* console.log(value);
|
|
896
|
+
* });
|
|
897
|
+
*
|
|
898
|
+
* // stableCallback can be safely used in useEffect deps without causing infinite loops
|
|
899
|
+
* useEffect(() => {
|
|
900
|
+
* stableCallback(someValue);
|
|
901
|
+
* }, [stableCallback]);
|
|
902
|
+
* ```
|
|
903
|
+
*/
|
|
904
|
+
declare function useMemoizedFn<T extends (...args: any[]) => any>(fn: T): T;
|
|
905
|
+
|
|
906
|
+
//#endregion
|
|
907
|
+
//#region src/useNetwork/useNetwork.d.ts
|
|
908
|
+
/**
|
|
909
|
+
* Represents the network state returned by useNetwork hook.
|
|
910
|
+
*/
|
|
911
|
+
type NetworkState = {
|
|
912
|
+
/** Whether the browser is online. */
|
|
913
|
+
online: boolean;
|
|
914
|
+
/** The estimated effective type of the connection. */
|
|
915
|
+
effectiveType: string | undefined;
|
|
916
|
+
/** The estimated downlink speed in Mbps. */
|
|
917
|
+
downlink: number | undefined;
|
|
918
|
+
/** The maximum downlink speed in Mbps. */
|
|
919
|
+
downlinkMax: number | undefined;
|
|
920
|
+
/** The type of connection (e.g., 'wifi', 'cellular'). */
|
|
921
|
+
type: string | undefined;
|
|
922
|
+
/** The effective round-trip time estimate in milliseconds. */
|
|
923
|
+
rtt: number | undefined;
|
|
924
|
+
/** Whether the user has requested a reduced data usage mode. */
|
|
925
|
+
saveData: boolean | undefined;
|
|
926
|
+
};
|
|
927
|
+
/**
|
|
928
|
+
* Custom hook that tracks the browser's network connection status.
|
|
929
|
+
* @returns {NetworkState} The current network state including online status and connection info.
|
|
930
|
+
* @public
|
|
931
|
+
* @see [Documentation](https://usehooks-ts.com/react-hook/use-network)
|
|
932
|
+
* @example
|
|
933
|
+
* ```tsx
|
|
934
|
+
* const { online, effectiveType, downlink } = useNetwork();
|
|
935
|
+
*
|
|
936
|
+
* return (
|
|
937
|
+
* <div>
|
|
938
|
+
* <p>Status: {online ? 'Online' : 'Offline'}</p>
|
|
939
|
+
* <p>Connection: {effectiveType}</p>
|
|
940
|
+
* <p>Speed: {downlink} Mbps</p>
|
|
941
|
+
* </div>
|
|
942
|
+
* );
|
|
943
|
+
* ```
|
|
944
|
+
*/
|
|
945
|
+
declare function useNetwork(): NetworkState;
|
|
946
|
+
|
|
947
|
+
//#endregion
|
|
948
|
+
//#region src/useOnClickOutside/useOnClickOutside.d.ts
|
|
949
|
+
/** Supported event types. */
|
|
950
|
+
type EventType = 'mousedown' | 'mouseup' | 'touchstart' | 'touchend' | 'focusin' | 'focusout';
|
|
951
|
+
/**
|
|
952
|
+
* Custom hook that handles clicks outside a specified element.
|
|
953
|
+
* @template T - The type of the element's reference.
|
|
954
|
+
* @param {RefObject<T | null> | RefObject<T | null>[]} ref - The React ref object(s) representing the element(s) to watch for outside clicks.
|
|
955
|
+
* @param {(event: MouseEvent | TouchEvent | FocusEvent) => void} handler - The callback function to be executed when a click outside the element occurs.
|
|
956
|
+
* @param {EventType} [eventType] - The mouse event type to listen for (optional, default is 'mousedown').
|
|
957
|
+
* @param {?AddEventListenerOptions} [eventListenerOptions] - The options object to be passed to the `addEventListener` method (optional).
|
|
958
|
+
* @returns {void}
|
|
959
|
+
* @public
|
|
960
|
+
* @see [Documentation](https://usehooks-ts.com/react-hook/use-on-click-outside)
|
|
961
|
+
* @example
|
|
962
|
+
* ```tsx
|
|
963
|
+
* const containerRef = useRef(null);
|
|
964
|
+
* useOnClickOutside([containerRef], () => {
|
|
965
|
+
* // Handle clicks outside the container.
|
|
966
|
+
* });
|
|
967
|
+
* ```
|
|
968
|
+
*/
|
|
969
|
+
declare function useOnClickOutside<T extends HTMLElement = HTMLElement>(ref: RefObject<T | null> | RefObject<T | null>[], handler: (event: MouseEvent | TouchEvent | FocusEvent) => void, eventType?: EventType, eventListenerOptions?: AddEventListenerOptions): void;
|
|
970
|
+
|
|
971
|
+
//#endregion
|
|
972
|
+
//#region src/usePageLeave/usePageLeave.d.ts
|
|
973
|
+
/**
|
|
974
|
+
* Custom hook that invokes a callback when the user's mouse leaves the page.
|
|
975
|
+
* @param {() => void} handler - The callback function to invoke when the mouse leaves the page.
|
|
976
|
+
* @public
|
|
977
|
+
* @see [Documentation](https://usehooks-ts.com/react-hook/use-page-leave)
|
|
978
|
+
* @example
|
|
979
|
+
* ```tsx
|
|
980
|
+
* usePageLeave(() => {
|
|
981
|
+
* console.log('User is leaving the page');
|
|
982
|
+
* // Show "Don't leave!" modal or save draft
|
|
983
|
+
* });
|
|
984
|
+
* ```
|
|
985
|
+
*/
|
|
986
|
+
declare function usePageLeave(handler: () => void): void;
|
|
987
|
+
|
|
988
|
+
//#endregion
|
|
989
|
+
//#region src/usePagination/usePagination.d.ts
|
|
990
|
+
/**
|
|
991
|
+
* Options for the usePagination hook.
|
|
992
|
+
*/
|
|
993
|
+
type UsePaginationOptions = {
|
|
994
|
+
/** Total number of pages. */
|
|
995
|
+
total: number;
|
|
996
|
+
/** Number of sibling pages to show on each side of current page. @default 1 */
|
|
997
|
+
siblings?: number;
|
|
998
|
+
/** Number of boundary pages to show at start and end. @default 1 */
|
|
999
|
+
boundaries?: number;
|
|
1000
|
+
/** Initial active page. @default 1 */
|
|
1001
|
+
initialPage?: number;
|
|
1002
|
+
/** Controlled active page (overrides internal state). */
|
|
1003
|
+
page?: number;
|
|
1004
|
+
/** Callback when page changes (for controlled mode). */
|
|
1005
|
+
onChange?: (page: number) => void;
|
|
1006
|
+
};
|
|
1007
|
+
/**
|
|
1008
|
+
* Represents the state and actions returned by usePagination hook.
|
|
1009
|
+
*/
|
|
1010
|
+
type UsePaginationReturn = {
|
|
1011
|
+
/** The currently active page number. */
|
|
1012
|
+
activePage: number;
|
|
1013
|
+
/** The pagination range (pages and separators). */
|
|
1014
|
+
range: (number | string)[];
|
|
1015
|
+
/** Set the active page. */
|
|
1016
|
+
setPage: (page: number) => void;
|
|
1017
|
+
/** Navigate to the next page. */
|
|
1018
|
+
next: () => void;
|
|
1019
|
+
/** Navigate to the previous page. */
|
|
1020
|
+
prev: () => void;
|
|
1021
|
+
/** Whether the current page is the first page. */
|
|
1022
|
+
first: boolean;
|
|
1023
|
+
/** Whether the current page is the last page. */
|
|
1024
|
+
last: boolean;
|
|
1025
|
+
};
|
|
1026
|
+
declare const DOTS = "dots";
|
|
1027
|
+
/**
|
|
1028
|
+
* Custom hook for managing pagination logic.
|
|
1029
|
+
* Returns page navigation functions and a range array suitable for pagination UI.
|
|
1030
|
+
* @param {UsePaginationOptions} options - Pagination configuration options.
|
|
1031
|
+
* @returns {UsePaginationReturn} The pagination state and navigation functions.
|
|
1032
|
+
* @public
|
|
1033
|
+
* @see [Documentation](https://usehooks-ts.com/react-hook/use-pagination)
|
|
1034
|
+
* @example
|
|
1035
|
+
* ```tsx
|
|
1036
|
+
* const { activePage, setPage, next, prev, range } = usePagination({
|
|
1037
|
+
* total: 20,
|
|
1038
|
+
* siblings: 1,
|
|
1039
|
+
* boundaries: 1,
|
|
1040
|
+
* });
|
|
1041
|
+
*
|
|
1042
|
+
* // range = [1, 'dots', 4, 5, 6, 'dots', 20]
|
|
1043
|
+
* ```
|
|
1044
|
+
*/
|
|
1045
|
+
declare function usePagination(options: UsePaginationOptions): UsePaginationReturn;
|
|
1046
|
+
|
|
1047
|
+
//#endregion
|
|
1048
|
+
//#region src/usePermission/usePermission.d.ts
|
|
1049
|
+
/**
|
|
1050
|
+
* Represents the state returned by usePermission hook.
|
|
1051
|
+
*/
|
|
1052
|
+
type PermissionState = {
|
|
1053
|
+
/** The current state of the permission. */
|
|
1054
|
+
state: PermissionStateValue;
|
|
1055
|
+
/** Whether the permission is supported by the browser. */
|
|
1056
|
+
supported: boolean;
|
|
1057
|
+
};
|
|
1058
|
+
/**
|
|
1059
|
+
* Valid permission state values.
|
|
1060
|
+
*/
|
|
1061
|
+
type PermissionStateValue = 'granted' | 'denied' | 'prompt' | 'unsupported';
|
|
1062
|
+
/**
|
|
1063
|
+
* Valid permission names for the Permissions API.
|
|
1064
|
+
*/
|
|
1065
|
+
type PermissionName = 'geolocation' | 'notifications' | 'push' | 'midi' | 'camera' | 'microphone' | 'speaker' | 'device-info' | 'background-fetch' | 'background-sync' | 'bluetooth' | 'persistent-storage' | 'ambient-light-sensor' | 'accelerometer' | 'gyroscope' | 'magnetometer' | 'clipboard' | 'display-capture' | 'nfc';
|
|
1066
|
+
/**
|
|
1067
|
+
* Custom hook that tracks the state of a browser permission.
|
|
1068
|
+
* @param {PermissionName} permissionName - The name of the permission to track.
|
|
1069
|
+
* @returns {PermissionState} The current state of the permission.
|
|
1070
|
+
* @public
|
|
1071
|
+
* @see [Documentation](https://usehooks-ts.com/react-hook/use-permission)
|
|
1072
|
+
* @example
|
|
1073
|
+
* ```tsx
|
|
1074
|
+
* const { state, supported } = usePermission('camera');
|
|
1075
|
+
*
|
|
1076
|
+
* if (!supported) return <div>Permissions API not supported</div>;
|
|
1077
|
+
* if (state === 'denied') return <div>Camera access denied</div>;
|
|
1078
|
+
* return <Camera />;
|
|
1079
|
+
* ```
|
|
1080
|
+
*/
|
|
1081
|
+
declare function usePermission(permissionName: PermissionName): PermissionState;
|
|
1082
|
+
|
|
1083
|
+
//#endregion
|
|
1084
|
+
//#region src/usePrevious/usePrevious.d.ts
|
|
1085
|
+
/**
|
|
1086
|
+
* Returns the previous value of a variable from the last render.
|
|
1087
|
+
* On the first render, returns `undefined` or the provided initial value.
|
|
1088
|
+
*
|
|
1089
|
+
* @template T - The type of the value being tracked
|
|
1090
|
+
* @param value - The current value to track
|
|
1091
|
+
* @returns The value from the previous render
|
|
1092
|
+
*
|
|
1093
|
+
* @example
|
|
1094
|
+
* ```tsx
|
|
1095
|
+
* function Counter() {
|
|
1096
|
+
* const [count, setCount] = useState(0)
|
|
1097
|
+
* const prevCount = usePrevious(count)
|
|
1098
|
+
*
|
|
1099
|
+
* return (
|
|
1100
|
+
* <div>
|
|
1101
|
+
* <p>Now: {count}, before: {prevCount}</p>
|
|
1102
|
+
* <button onClick={() => setCount(c => c + 1)}>Increment</button>
|
|
1103
|
+
* </div>
|
|
1104
|
+
* )
|
|
1105
|
+
* }
|
|
1106
|
+
* ```
|
|
1107
|
+
*/
|
|
1108
|
+
declare function usePrevious<T>(value: T): T | undefined;
|
|
1109
|
+
declare function usePrevious<T, I>(value: T, initialValue: I): T | I;
|
|
1110
|
+
|
|
1111
|
+
//#endregion
|
|
1112
|
+
//#region src/useQueue/useQueue.d.ts
|
|
1113
|
+
/**
|
|
1114
|
+
* Represents the actions available to interact with the queue state.
|
|
1115
|
+
* @template T - The type of elements in the queue.
|
|
1116
|
+
*/
|
|
1117
|
+
type UseQueueActions<T> = {
|
|
1118
|
+
/** Add a value to the end of the queue. */
|
|
1119
|
+
add: (value: T) => void;
|
|
1120
|
+
/** Remove and return the value from the front of the queue (FIFO). */
|
|
1121
|
+
remove: () => T | undefined;
|
|
1122
|
+
/** Clear all values from the queue. */
|
|
1123
|
+
clear: () => void;
|
|
1124
|
+
/** The first (front) value in the queue. */
|
|
1125
|
+
first: T | undefined;
|
|
1126
|
+
/** The last (back) value in the queue. */
|
|
1127
|
+
last: T | undefined;
|
|
1128
|
+
/** The number of elements in the queue. */
|
|
1129
|
+
size: number;
|
|
1130
|
+
};
|
|
1131
|
+
/**
|
|
1132
|
+
* Represents the return type of the `useQueue` hook.
|
|
1133
|
+
* @template T - The type of elements in the queue.
|
|
1134
|
+
*/
|
|
1135
|
+
type UseQueueReturn<T> = [T[], UseQueueActions<T>];
|
|
1136
|
+
/**
|
|
1137
|
+
* Custom hook that manages a FIFO (First In, First Out) queue state with setter actions.
|
|
1138
|
+
* @template T - The type of elements in the queue.
|
|
1139
|
+
* @param {T[]} [initialValue] - The initial array of values for the queue (optional).
|
|
1140
|
+
* @returns {UseQueueReturn<T>} A tuple containing the queue state and actions to interact with the queue.
|
|
1141
|
+
* @public
|
|
1142
|
+
* @see [Documentation](https://usehooks-ts.com/react-hook/use-queue)
|
|
1143
|
+
* @example
|
|
1144
|
+
* ```tsx
|
|
1145
|
+
* const [queue, queueActions] = useQueue<number>([1, 2, 3]);
|
|
1146
|
+
* // Access the `queue` array and use `queueActions` to add, remove, or clear values.
|
|
1147
|
+
* ```
|
|
1148
|
+
*/
|
|
1149
|
+
declare function useQueue<T>(initialValue?: T[]): UseQueueReturn<T>;
|
|
1150
|
+
|
|
1151
|
+
//#endregion
|
|
1152
|
+
//#region src/useReadLocalStorage/useReadLocalStorage.d.ts
|
|
1153
|
+
/**
|
|
1154
|
+
* Represents the type for the options available when reading from local storage.
|
|
1155
|
+
* @template T - The type of the stored value.
|
|
1156
|
+
*/
|
|
1157
|
+
type Options<T, InitializeWithValue extends boolean | undefined> = {
|
|
1158
|
+
/** Custom deserializer function to convert the stored string value to the desired type (optional). */
|
|
1159
|
+
deserializer?: (value: string) => T;
|
|
1160
|
+
/** If `true` (default), the hook will initialize reading the local storage. In SSR, you should set it to `false`, returning `undefined` initially. */
|
|
1161
|
+
initializeWithValue: InitializeWithValue;
|
|
1162
|
+
};
|
|
1163
|
+
declare function useReadLocalStorage<T>(key: string, options: Options<T, false>): T | null | undefined;
|
|
1164
|
+
declare function useReadLocalStorage<T>(key: string, options?: Partial<Options<T, true>>): T | null;
|
|
1165
|
+
|
|
1166
|
+
//#endregion
|
|
1167
|
+
//#region src/useResizeObserver/useResizeObserver.d.ts
|
|
1168
|
+
/** The size of the observed element. */
|
|
1169
|
+
type Size = {
|
|
1170
|
+
/** The width of the observed element. */
|
|
1171
|
+
width: number | undefined;
|
|
1172
|
+
/** The height of the observed element. */
|
|
1173
|
+
height: number | undefined;
|
|
1174
|
+
};
|
|
1175
|
+
/** The options for the ResizeObserver. */
|
|
1176
|
+
type UseResizeObserverOptions<T extends HTMLElement = HTMLElement> = {
|
|
1177
|
+
/** The ref of the element to observe. */
|
|
1178
|
+
ref: RefObject<T | null>;
|
|
1179
|
+
/**
|
|
1180
|
+
* When using `onResize`, the hook doesn't re-render on element size changes; it delegates handling to the provided callback.
|
|
1181
|
+
* @default undefined
|
|
1182
|
+
*/
|
|
1183
|
+
onResize?: (size: Size) => void;
|
|
1184
|
+
/**
|
|
1185
|
+
* The box model to use for the ResizeObserver.
|
|
1186
|
+
* @default 'content-box'
|
|
1187
|
+
*/
|
|
1188
|
+
box?: 'border-box' | 'content-box' | 'device-pixel-content-box';
|
|
1189
|
+
};
|
|
1190
|
+
/**
|
|
1191
|
+
* Custom hook that observes the size of an element using the [`ResizeObserver API`](https://developer.mozilla.org/en-US/docs/Web/API/ResizeObserver).
|
|
1192
|
+
* @template T - The type of the element to observe.
|
|
1193
|
+
* @param {UseResizeObserverOptions<T>} options - The options for the ResizeObserver.
|
|
1194
|
+
* @returns {Size} - The size of the observed element.
|
|
1195
|
+
* @public
|
|
1196
|
+
* @see [Documentation](https://usehooks-ts.com/react-hook/use-resize-observer)
|
|
1197
|
+
* @example
|
|
1198
|
+
* ```tsx
|
|
1199
|
+
* const myRef = useRef(null);
|
|
1200
|
+
* const { width = 0, height = 0 } = useResizeObserver({
|
|
1201
|
+
* ref: myRef,
|
|
1202
|
+
* box: 'content-box',
|
|
1203
|
+
* });
|
|
1204
|
+
*
|
|
1205
|
+
* <div ref={myRef}>Hello, world!</div>
|
|
1206
|
+
* ```
|
|
1207
|
+
*/
|
|
1208
|
+
declare function useResizeObserver<T extends HTMLElement = HTMLElement>(options: UseResizeObserverOptions<T>): Size;
|
|
1209
|
+
|
|
1210
|
+
//#endregion
|
|
1211
|
+
//#region src/useScreen/useScreen.d.ts
|
|
1212
|
+
/**
|
|
1213
|
+
* The hooks options.
|
|
1214
|
+
* @template InitializeWithValue - If `true` (default), the hook will initialize reading the screen dimensions. In SSR, you should set it to `false`, returning `undefined` initially.
|
|
1215
|
+
*/
|
|
1216
|
+
type UseScreenOptions<InitializeWithValue extends boolean | undefined> = {
|
|
1217
|
+
/**
|
|
1218
|
+
* If `true` (default), the hook will initialize reading the screen dimensions. In SSR, you should set it to `false`, returning `undefined` initially.
|
|
1219
|
+
* @default true
|
|
1220
|
+
*/
|
|
1221
|
+
initializeWithValue: InitializeWithValue;
|
|
1222
|
+
/**
|
|
1223
|
+
* The delay in milliseconds before the state is updated (disabled by default for retro-compatibility).
|
|
1224
|
+
* @default undefined
|
|
1225
|
+
*/
|
|
1226
|
+
debounceDelay?: number;
|
|
1227
|
+
};
|
|
1228
|
+
declare function useScreen(options: UseScreenOptions<false>): Screen | undefined;
|
|
1229
|
+
declare function useScreen(options?: Partial<UseScreenOptions<true>>): Screen;
|
|
1230
|
+
|
|
1231
|
+
//#endregion
|
|
1232
|
+
//#region src/useScript/useScript.d.ts
|
|
1233
|
+
/** Script loading status. */
|
|
1234
|
+
type UseScriptStatus = 'idle' | 'loading' | 'ready' | 'error';
|
|
1235
|
+
/** Hook options. */
|
|
1236
|
+
type UseScriptOptions = {
|
|
1237
|
+
/** If `true`, prevents the script from being loaded (optional). */
|
|
1238
|
+
shouldPreventLoad?: boolean;
|
|
1239
|
+
/** If `true`, removes the script from the DOM when the component unmounts (optional). */
|
|
1240
|
+
removeOnUnmount?: boolean;
|
|
1241
|
+
/** Script's `id` (optional). */
|
|
1242
|
+
id?: string;
|
|
1243
|
+
};
|
|
1244
|
+
/**
|
|
1245
|
+
* Custom hook that dynamically loads scripts and tracking their loading status.
|
|
1246
|
+
* @param {string | null} src - The source URL of the script to load. Set to `null` or omit to prevent loading (optional).
|
|
1247
|
+
* @param {UseScriptOptions} [options] - Additional options for controlling script loading (optional).
|
|
1248
|
+
* @returns {UseScriptStatus} The status of the script loading, which can be one of 'idle', 'loading', 'ready', or 'error'.
|
|
1249
|
+
* @see [Documentation](https://usehooks-ts.com/react-hook/use-script)
|
|
1250
|
+
* @example
|
|
1251
|
+
* const scriptStatus = useScript('https://example.com/script.js', { removeOnUnmount: true });
|
|
1252
|
+
* // Access the status of the script loading (e.g., 'loading', 'ready', 'error').
|
|
1253
|
+
*/
|
|
1254
|
+
declare function useScript(src: string | null, options?: UseScriptOptions): UseScriptStatus;
|
|
1255
|
+
|
|
1256
|
+
//#endregion
|
|
1257
|
+
//#region src/useScrollLock/useScrollLock.d.ts
|
|
1258
|
+
/** Hook options. */
|
|
1259
|
+
type UseScrollLockOptions = {
|
|
1260
|
+
/**
|
|
1261
|
+
* Whether to lock the scroll initially.
|
|
1262
|
+
* @default true
|
|
1263
|
+
*/
|
|
1264
|
+
autoLock?: boolean;
|
|
1265
|
+
/**
|
|
1266
|
+
* The target element to lock the scroll (default is the body element).
|
|
1267
|
+
* @default document.body
|
|
1268
|
+
*/
|
|
1269
|
+
lockTarget?: HTMLElement | string;
|
|
1270
|
+
/**
|
|
1271
|
+
* Whether to prevent width reflow when locking the scroll.
|
|
1272
|
+
* @default true
|
|
1273
|
+
*/
|
|
1274
|
+
widthReflow?: boolean;
|
|
1275
|
+
};
|
|
1276
|
+
/** Hook return type. */
|
|
1277
|
+
type UseScrollLockReturn = {
|
|
1278
|
+
/** Whether the scroll is locked. */
|
|
1279
|
+
isLocked: boolean;
|
|
1280
|
+
/** Lock the scroll. */
|
|
1281
|
+
lock: () => void;
|
|
1282
|
+
/** Unlock the scroll. */
|
|
1283
|
+
unlock: () => void;
|
|
1284
|
+
};
|
|
1285
|
+
type OriginalStyle = {
|
|
1286
|
+
overflow: CSSStyleDeclaration['overflow'];
|
|
1287
|
+
paddingRight: CSSStyleDeclaration['paddingRight'];
|
|
1288
|
+
};
|
|
1289
|
+
/**
|
|
1290
|
+
* A custom hook that locks and unlocks scroll.
|
|
1291
|
+
* @param {UseScrollLockOptions} [options] - Options to configure the hook, by default it will lock the scroll automatically.
|
|
1292
|
+
* @returns {UseScrollLockReturn} - An object containing the lock and unlock functions.
|
|
1293
|
+
* @public
|
|
1294
|
+
* @see [Documentation](https://usehooks-ts.com/react-hook/use-scroll-lock)
|
|
1295
|
+
* @example
|
|
1296
|
+
* ```tsx
|
|
1297
|
+
* // Lock the scroll when the modal is mounted, and unlock it when it's unmounted
|
|
1298
|
+
* useScrollLock()
|
|
1299
|
+
* ```
|
|
1300
|
+
* @example
|
|
1301
|
+
* ```tsx
|
|
1302
|
+
* // Manually lock and unlock the scroll
|
|
1303
|
+
* const { lock, unlock } = useScrollLock({ autoLock: false })
|
|
1304
|
+
*
|
|
1305
|
+
* return (
|
|
1306
|
+
* <div>
|
|
1307
|
+
* <button onClick={lock}>Lock</button>
|
|
1308
|
+
* <button onClick={unlock}>Unlock</button>
|
|
1309
|
+
* </div>
|
|
1310
|
+
* )
|
|
1311
|
+
* ```
|
|
1312
|
+
*/
|
|
1313
|
+
declare function useScrollLock(options?: UseScrollLockOptions): UseScrollLockReturn;
|
|
1314
|
+
|
|
1315
|
+
//#endregion
|
|
1316
|
+
//#region src/useSessionStorage/useSessionStorage.d.ts
|
|
1317
|
+
declare global {
|
|
1318
|
+
interface WindowEventMap {
|
|
1319
|
+
'session-storage': CustomEvent;
|
|
1320
|
+
}
|
|
1321
|
+
}
|
|
1322
|
+
/**
|
|
1323
|
+
* Represents the options for customizing the behavior of serialization and deserialization.
|
|
1324
|
+
* @template T - The type of the state to be stored in session storage.
|
|
1325
|
+
*/
|
|
1326
|
+
type UseSessionStorageOptions<T> = {
|
|
1327
|
+
/** A function to serialize the value before storing it. */
|
|
1328
|
+
serializer?: (value: T) => string;
|
|
1329
|
+
/** A function to deserialize the stored value. */
|
|
1330
|
+
deserializer?: (value: string) => T;
|
|
1331
|
+
/**
|
|
1332
|
+
* If `true` (default), the hook will initialize reading the session storage. In SSR, you should set it to `false`, returning the initial value initially.
|
|
1333
|
+
* @default true
|
|
1334
|
+
*/
|
|
1335
|
+
initializeWithValue?: boolean;
|
|
1336
|
+
};
|
|
1337
|
+
/**
|
|
1338
|
+
* Custom hook that uses the [`sessionStorage API`](https://developer.mozilla.org/en-US/docs/Web/API/Window/sessionStorage) to persist state across page reloads.
|
|
1339
|
+
* @template T - The type of the state to be stored in session storage.
|
|
1340
|
+
* @param {string} key - The key under which the value will be stored in session storage.
|
|
1341
|
+
* @param {T | (() => T)} initialValue - The initial value of the state or a function that returns the initial value.
|
|
1342
|
+
* @param {?UseSessionStorageOptions<T>} [options] - Options for customizing the behavior of serialization and deserialization (optional).
|
|
1343
|
+
* @returns {[T, Dispatch<SetStateAction<T>>, () => void]} A tuple containing the stored value, a function to set the value and a function to remove the key from storage.
|
|
1344
|
+
* @public
|
|
1345
|
+
* @see [Documentation](https://usehooks-ts.com/react-hook/use-session-storage)
|
|
1346
|
+
* @example
|
|
1347
|
+
* ```tsx
|
|
1348
|
+
* const [count, setCount, removeCount] = useSessionStorage('count', 0);
|
|
1349
|
+
* // Access the `count` value, the `setCount` function to update it and `removeCount` function to remove the key from storage.
|
|
1350
|
+
* ```
|
|
1351
|
+
*/
|
|
1352
|
+
declare function useSessionStorage<T>(key: string, initialValue: T | (() => T), options?: UseSessionStorageOptions<T>): [T, Dispatch<SetStateAction<T>>, () => void];
|
|
1353
|
+
|
|
1354
|
+
//#endregion
|
|
1355
|
+
//#region src/useSet/useSet.d.ts
|
|
1356
|
+
/**
|
|
1357
|
+
* Represents the actions available to interact with the set state.
|
|
1358
|
+
* @template T - The type of elements in the set.
|
|
1359
|
+
*/
|
|
1360
|
+
type UseSetActions<T> = {
|
|
1361
|
+
/** Add a value to the set. */
|
|
1362
|
+
add: (value: T) => void;
|
|
1363
|
+
/** Remove a value from the set. */
|
|
1364
|
+
remove: (value: T) => void;
|
|
1365
|
+
/** Toggle a value in the set (add if not present, remove if present). */
|
|
1366
|
+
toggle: (value: T) => void;
|
|
1367
|
+
/** Check if a value exists in the set. */
|
|
1368
|
+
has: (value: T) => boolean;
|
|
1369
|
+
/** Clear all values from the set. */
|
|
1370
|
+
clear: () => void;
|
|
1371
|
+
/** Reset the set to its initial state. */
|
|
1372
|
+
reset: () => void;
|
|
1373
|
+
};
|
|
1374
|
+
/**
|
|
1375
|
+
* Represents the return type of the `useSet` hook.
|
|
1376
|
+
* We hide some setters from the returned set to disable autocompletion.
|
|
1377
|
+
* @template T - The type of elements in the set.
|
|
1378
|
+
*/
|
|
1379
|
+
type UseSetReturn<T> = [Omit<Set<T>, 'add' | 'clear' | 'delete'>, UseSetActions<T>];
|
|
1380
|
+
/**
|
|
1381
|
+
* Custom hook that manages a [`Set`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set) state with setter actions.
|
|
1382
|
+
* @template T - The type of elements in the set.
|
|
1383
|
+
* @param {Set<T> | T[]} [initialValue] - The initial value of the set as a Set or an array of values (optional).
|
|
1384
|
+
* @returns {UseSetReturn<T>} A tuple containing the set state and actions to interact with the set.
|
|
1385
|
+
* @public
|
|
1386
|
+
* @see [Documentation](https://usehooks-ts.com/react-hook/use-set)
|
|
1387
|
+
* @example
|
|
1388
|
+
* ```tsx
|
|
1389
|
+
* const [set, setActions] = useSet<string>(['hello']);
|
|
1390
|
+
* // Access the `set` state and use `setActions` to add, remove, toggle, or reset values.
|
|
1391
|
+
* ```
|
|
1392
|
+
*/
|
|
1393
|
+
declare function useSet<T>(initialValue?: Set<T> | T[]): UseSetReturn<T>;
|
|
1394
|
+
|
|
1395
|
+
//#endregion
|
|
1396
|
+
//#region src/useStateList/useStateList.d.ts
|
|
1397
|
+
/**
|
|
1398
|
+
* Represents the state and actions returned by useStateList hook.
|
|
1399
|
+
* @template T - The type of the state values.
|
|
1400
|
+
*/
|
|
1401
|
+
type UseStateListReturn<T> = {
|
|
1402
|
+
/** The current state value. */
|
|
1403
|
+
state: T;
|
|
1404
|
+
/** The current index in the state list. */
|
|
1405
|
+
currentIndex: number;
|
|
1406
|
+
/** Whether the current state is the first in the list. */
|
|
1407
|
+
isFirst: boolean;
|
|
1408
|
+
/** Whether the current state is the last in the list. */
|
|
1409
|
+
isLast: boolean;
|
|
1410
|
+
/** Navigate to the previous state. */
|
|
1411
|
+
prev: () => void;
|
|
1412
|
+
/** Navigate to the next state. */
|
|
1413
|
+
next: () => void;
|
|
1414
|
+
/** Set the state by index. */
|
|
1415
|
+
setStateAt: (index: number) => void;
|
|
1416
|
+
/** Set the state by value. */
|
|
1417
|
+
setState: (state: T) => void;
|
|
1418
|
+
};
|
|
1419
|
+
/**
|
|
1420
|
+
* Custom hook for navigating through a list of states.
|
|
1421
|
+
* Useful for step-by-step flows, carousels, or multi-step forms.
|
|
1422
|
+
* @template T - The type of the state values.
|
|
1423
|
+
* @param {T[]} stateSet - The array of possible states.
|
|
1424
|
+
* @returns {UseStateListReturn<T>} The current state and navigation functions.
|
|
1425
|
+
* @public
|
|
1426
|
+
* @see [Documentation](https://usehooks-ts.com/react-hook/use-state-list)
|
|
1427
|
+
* @example
|
|
1428
|
+
* ```tsx
|
|
1429
|
+
* const states = ['step1', 'step2', 'step3'];
|
|
1430
|
+
* const { state, next, prev, isFirst, isLast } = useStateList(states);
|
|
1431
|
+
*
|
|
1432
|
+
* return (
|
|
1433
|
+
* <div>
|
|
1434
|
+
* <p>Current: {state}</p>
|
|
1435
|
+
* <button onClick={prev} disabled={isFirst}>Back</button>
|
|
1436
|
+
* <button onClick={next} disabled={isLast}>Next</button>
|
|
1437
|
+
* </div>
|
|
1438
|
+
* );
|
|
1439
|
+
* ```
|
|
1440
|
+
*/
|
|
1441
|
+
declare function useStateList<T>(stateSet: T[]): UseStateListReturn<T>;
|
|
1442
|
+
|
|
1443
|
+
//#endregion
|
|
1444
|
+
//#region src/useStep/useStep.d.ts
|
|
1445
|
+
/** Represents the second element of the output of the `useStep` hook. */
|
|
1446
|
+
type UseStepActions = {
|
|
1447
|
+
/** Go to the next step in the process. */
|
|
1448
|
+
goToNextStep: () => void;
|
|
1449
|
+
/** Go to the previous step in the process. */
|
|
1450
|
+
goToPrevStep: () => void;
|
|
1451
|
+
/** Reset the step to the initial step. */
|
|
1452
|
+
reset: () => void;
|
|
1453
|
+
/** Check if the next step is available. */
|
|
1454
|
+
canGoToNextStep: boolean;
|
|
1455
|
+
/** Check if the previous step is available. */
|
|
1456
|
+
canGoToPrevStep: boolean;
|
|
1457
|
+
/** Set the current step to a specific value. */
|
|
1458
|
+
setStep: Dispatch<SetStateAction<number>>;
|
|
1459
|
+
};
|
|
1460
|
+
type SetStepCallbackType = (step: number | ((step: number) => number)) => void;
|
|
1461
|
+
/**
|
|
1462
|
+
* Custom hook that manages and navigates between steps in a multi-step process.
|
|
1463
|
+
* @param {number} maxStep - The maximum step in the process.
|
|
1464
|
+
* @returns {[number, UseStepActions]} An tuple containing the current step and helper functions for navigating steps.
|
|
1465
|
+
* @public
|
|
1466
|
+
* @see [Documentation](https://usehooks-ts.com/react-hook/use-step)
|
|
1467
|
+
* @example
|
|
1468
|
+
* ```tsx
|
|
1469
|
+
* const [currentStep, { goToNextStep, goToPrevStep, reset, canGoToNextStep, canGoToPrevStep, setStep }] = useStep(3);
|
|
1470
|
+
* // Access and use the current step and provided helper functions.
|
|
1471
|
+
* ```
|
|
1472
|
+
*/
|
|
1473
|
+
declare function useStep(maxStep: number): [number, UseStepActions];
|
|
1474
|
+
|
|
1475
|
+
//#endregion
|
|
1476
|
+
//#region src/useTernaryDarkMode/useTernaryDarkMode.d.ts
|
|
1477
|
+
/** Ternary dark mode options. */
|
|
1478
|
+
type TernaryDarkMode = 'system' | 'dark' | 'light';
|
|
1479
|
+
/** Options for the `useTernaryDarkMode` hook. */
|
|
1480
|
+
type TernaryDarkModeOptions = {
|
|
1481
|
+
/**
|
|
1482
|
+
* The default value for the dark mode.
|
|
1483
|
+
* @default 'system'
|
|
1484
|
+
*/
|
|
1485
|
+
defaultValue?: TernaryDarkMode;
|
|
1486
|
+
/**
|
|
1487
|
+
* The key for storing dark mode preference in local storage.
|
|
1488
|
+
* @default 'usehooks-ts-ternary-dark-mode'
|
|
1489
|
+
*/
|
|
1490
|
+
localStorageKey?: string;
|
|
1491
|
+
/**
|
|
1492
|
+
* If `true` (default), the hook will initialize reading `localStorage`. In SSR, you should set it to `false`, returning default values initially.
|
|
1493
|
+
* @default true
|
|
1494
|
+
*/
|
|
1495
|
+
initializeWithValue?: boolean;
|
|
1496
|
+
};
|
|
1497
|
+
/** Represents the return type of the `useTernaryDarkMode` hook. */
|
|
1498
|
+
type TernaryDarkModeReturn = {
|
|
1499
|
+
/** The current state of the dark mode. */
|
|
1500
|
+
isDarkMode: boolean;
|
|
1501
|
+
/** The current state of the dark mode. */
|
|
1502
|
+
ternaryDarkMode: TernaryDarkMode;
|
|
1503
|
+
/** A function to set the dark mode state. */
|
|
1504
|
+
setTernaryDarkMode: Dispatch<SetStateAction<TernaryDarkMode>>;
|
|
1505
|
+
/** A function to toggle the dark mode state. */
|
|
1506
|
+
toggleTernaryDarkMode: () => void;
|
|
1507
|
+
};
|
|
1508
|
+
/**
|
|
1509
|
+
* Custom hook that manages ternary (system, dark, light) dark mode with local storage support.
|
|
1510
|
+
* @param {?TernaryDarkModeOptions | string} [options] - Options or the local storage key for the hook.
|
|
1511
|
+
* @returns {TernaryDarkModeReturn} An object containing the dark mode state and helper functions.
|
|
1512
|
+
* @public
|
|
1513
|
+
* @see [Documentation](https://usehooks-ts.com/react-hook/use-ternary-dark-mode)
|
|
1514
|
+
* @example
|
|
1515
|
+
* ```tsx
|
|
1516
|
+
* const { isDarkMode, ternaryDarkMode, setTernaryDarkMode, toggleTernaryDarkMode } = useTernaryDarkMode({ defaultValue: 'dark' });
|
|
1517
|
+
* // Access and use the dark mode state and provided helper functions.
|
|
1518
|
+
* ```
|
|
1519
|
+
*/
|
|
1520
|
+
declare function useTernaryDarkMode({
|
|
1521
|
+
defaultValue,
|
|
1522
|
+
localStorageKey,
|
|
1523
|
+
initializeWithValue
|
|
1524
|
+
}?: TernaryDarkModeOptions): TernaryDarkModeReturn;
|
|
1525
|
+
|
|
1526
|
+
//#endregion
|
|
1527
|
+
//#region src/useThrottle/useThrottle.d.ts
|
|
1528
|
+
/**
|
|
1529
|
+
* Custom hook that throttles a function, ensuring it is only called at most once per wait period.
|
|
1530
|
+
* @template T - The type of the function being throttled.
|
|
1531
|
+
* @param {T} fn - The function to throttle.
|
|
1532
|
+
* @param {number} wait - The number of milliseconds to throttle invocations to.
|
|
1533
|
+
* @returns {T} The throttled function.
|
|
1534
|
+
* @public
|
|
1535
|
+
* @see [Documentation](https://usehooks-ts.com/react-hook/use-throttle-fn)
|
|
1536
|
+
* @example
|
|
1537
|
+
* ```tsx
|
|
1538
|
+
* const throttledSave = useThrottleFn(saveToDatabase, 1000);
|
|
1539
|
+
* // Calling throttledSave() multiple times rapidly will only execute saveToDatabase once per second
|
|
1540
|
+
* ```
|
|
1541
|
+
*/
|
|
1542
|
+
declare function useThrottleFn<T extends (...args: any[]) => any>(fn: T, wait: number): T;
|
|
1543
|
+
/**
|
|
1544
|
+
* Custom hook that throttles a value, ensuring updates occur at most once per wait period.
|
|
1545
|
+
* @template T - The type of the value being throttled.
|
|
1546
|
+
* @param {T} value - The value to throttle.
|
|
1547
|
+
* @param {number} wait - The number of milliseconds to throttle updates to.
|
|
1548
|
+
* @returns {T} The throttled value.
|
|
1549
|
+
* @public
|
|
1550
|
+
* @see [Documentation](https://usehooks-ts.com/react-hook/use-throttle)
|
|
1551
|
+
* @example
|
|
1552
|
+
* ```tsx
|
|
1553
|
+
* const throttledSearchTerm = useThrottle(searchTerm, 300);
|
|
1554
|
+
* // throttledSearchTerm will only update 300ms after the last change to searchTerm
|
|
1555
|
+
* ```
|
|
1556
|
+
*/
|
|
1557
|
+
declare function useThrottle<T>(value: T, wait: number): T;
|
|
1558
|
+
|
|
1559
|
+
//#endregion
|
|
1560
|
+
//#region src/useTimeout/useTimeout.d.ts
|
|
1561
|
+
/**
|
|
1562
|
+
* Custom hook that handles timeouts in React components using the [`setTimeout API`](https://developer.mozilla.org/en-US/docs/Web/API/WindowOrWorkerGlobalScope/setTimeout).
|
|
1563
|
+
* @param {() => void} callback - The function to be executed when the timeout elapses.
|
|
1564
|
+
* @param {number | null} delay - The duration (in milliseconds) for the timeout. Set to `null` to clear the timeout.
|
|
1565
|
+
* @returns {void} This hook does not return anything.
|
|
1566
|
+
* @public
|
|
1567
|
+
* @see [Documentation](https://usehooks-ts.com/react-hook/use-timeout)
|
|
1568
|
+
* @example
|
|
1569
|
+
* ```tsx
|
|
1570
|
+
* // Usage of useTimeout hook
|
|
1571
|
+
* useTimeout(() => {
|
|
1572
|
+
* // Code to be executed after the specified delay
|
|
1573
|
+
* }, 1000); // Set a timeout of 1000 milliseconds (1 second)
|
|
1574
|
+
* ```
|
|
1575
|
+
*/
|
|
1576
|
+
declare function useTimeout(callback: () => void, delay: number | null): void;
|
|
1577
|
+
|
|
1578
|
+
//#endregion
|
|
1579
|
+
//#region src/useToggle/useToggle.d.ts
|
|
1580
|
+
/**
|
|
1581
|
+
* Custom hook that manages a boolean toggle state in React components.
|
|
1582
|
+
* @param {boolean} [defaultValue] - The initial value for the toggle state.
|
|
1583
|
+
* @returns {[boolean, () => void, Dispatch<SetStateAction<boolean>>]} A tuple containing the current state,
|
|
1584
|
+
* a function to toggle the state, and a function to set the state explicitly.
|
|
1585
|
+
* @public
|
|
1586
|
+
* @see [Documentation](https://usehooks-ts.com/react-hook/use-toggle)
|
|
1587
|
+
* @example
|
|
1588
|
+
* ```tsx
|
|
1589
|
+
* const [isToggled, toggle, setToggle] = useToggle(); // Initial value is false
|
|
1590
|
+
* // OR
|
|
1591
|
+
* const [isToggled, toggle, setToggle] = useToggle(true); // Initial value is true
|
|
1592
|
+
* // Use isToggled in your component, toggle to switch the state, setToggle to set the state explicitly.
|
|
1593
|
+
* ```
|
|
1594
|
+
*/
|
|
1595
|
+
declare function useToggle(defaultValue?: boolean): [boolean, () => void, Dispatch<SetStateAction<boolean>>];
|
|
1596
|
+
|
|
1597
|
+
//#endregion
|
|
1598
|
+
//#region src/useUnmount/useUnmount.d.ts
|
|
1599
|
+
/**
|
|
1600
|
+
* Custom hook that runs a cleanup function when the component is unmounted.
|
|
1601
|
+
* @param {() => void} func - The cleanup function to be executed on unmount.
|
|
1602
|
+
* @public
|
|
1603
|
+
* @see [Documentation](https://usehooks-ts.com/react-hook/use-unmount)
|
|
1604
|
+
* @example
|
|
1605
|
+
* ```tsx
|
|
1606
|
+
* useUnmount(() => {
|
|
1607
|
+
* // Cleanup logic here
|
|
1608
|
+
* });
|
|
1609
|
+
* ```
|
|
1610
|
+
*/
|
|
1611
|
+
declare function useUnmount(func: () => void): void;
|
|
1612
|
+
|
|
1613
|
+
//#endregion
|
|
1614
|
+
//#region src/useUpdate/useUpdate.d.ts
|
|
1615
|
+
/**
|
|
1616
|
+
* Custom hook that returns a function to force a component re-render.
|
|
1617
|
+
* @returns {() => void} A function that, when called, will force the component to re-render.
|
|
1618
|
+
* @public
|
|
1619
|
+
* @see [Documentation](https://usehooks-ts.com/react-hook/use-update)
|
|
1620
|
+
* @example
|
|
1621
|
+
* ```tsx
|
|
1622
|
+
* const update = useUpdate();
|
|
1623
|
+
*
|
|
1624
|
+
* return (
|
|
1625
|
+
* <div>
|
|
1626
|
+
* <p>Current time: {Date.now()}</p>
|
|
1627
|
+
* <button onClick={update}>Update</button>
|
|
1628
|
+
* </div>
|
|
1629
|
+
* );
|
|
1630
|
+
* ```
|
|
1631
|
+
*/
|
|
1632
|
+
declare function useUpdate(): () => void;
|
|
1633
|
+
|
|
1634
|
+
//#endregion
|
|
1635
|
+
//#region src/useUpdateEffect/useUpdateEffect.d.ts
|
|
1636
|
+
/**
|
|
1637
|
+
* A hook that runs an effect only when dependencies change, skipping the initial mount.
|
|
1638
|
+
* This is useful for responding to prop or state changes without running on first render.
|
|
1639
|
+
*
|
|
1640
|
+
* @param {() => void | (() => void)} effect - The effect function to run.
|
|
1641
|
+
* @param {unknown[]} deps - The dependency array.
|
|
1642
|
+
*
|
|
1643
|
+
* @example
|
|
1644
|
+
* ```tsx
|
|
1645
|
+
* function Component({ value }) {
|
|
1646
|
+
* useUpdateEffect(() => {
|
|
1647
|
+
* console.log('Value changed:', value);
|
|
1648
|
+
* }, [value]);
|
|
1649
|
+
*
|
|
1650
|
+
* return <div>{value}</div>;
|
|
1651
|
+
* }
|
|
1652
|
+
* ```
|
|
1653
|
+
*/
|
|
1654
|
+
declare function useUpdateEffect(effect: () => void | (() => void), deps: unknown[]): void;
|
|
1655
|
+
|
|
1656
|
+
//#endregion
|
|
1657
|
+
//#region src/useWindowSize/useWindowSize.d.ts
|
|
1658
|
+
/**
|
|
1659
|
+
* Represent the dimension of the window.
|
|
1660
|
+
* @template T - The type of the dimension (number or undefined).
|
|
1661
|
+
*/
|
|
1662
|
+
type WindowSize<T extends number | undefined = number | undefined> = {
|
|
1663
|
+
/** The width of the window. */
|
|
1664
|
+
width: T;
|
|
1665
|
+
/** The height of the window. */
|
|
1666
|
+
height: T;
|
|
1667
|
+
};
|
|
1668
|
+
/**
|
|
1669
|
+
* Hook options.
|
|
1670
|
+
* @template InitializeWithValue - If `true` (default), the hook will initialize reading the window size. In SSR, you should set it to `false`, returning `undefined` initially.
|
|
1671
|
+
*/
|
|
1672
|
+
type UseWindowSizeOptions<InitializeWithValue extends boolean | undefined> = {
|
|
1673
|
+
/**
|
|
1674
|
+
* If `true` (default), the hook will initialize reading the window size. In SSR, you should set it to `false`, returning `undefined` initially.
|
|
1675
|
+
* @default true
|
|
1676
|
+
*/
|
|
1677
|
+
initializeWithValue: InitializeWithValue;
|
|
1678
|
+
/**
|
|
1679
|
+
* The delay in milliseconds before the state is updated (disabled by default for retro-compatibility).
|
|
1680
|
+
* @default undefined
|
|
1681
|
+
*/
|
|
1682
|
+
debounceDelay?: number;
|
|
1683
|
+
};
|
|
1684
|
+
declare function useWindowSize(options: UseWindowSizeOptions<false>): WindowSize;
|
|
1685
|
+
declare function useWindowSize(options?: Partial<UseWindowSizeOptions<true>>): WindowSize<number>;
|
|
1686
|
+
|
|
1687
|
+
//#endregion
|
|
1688
|
+
export { ControlFunctions, CopiedValue, CopyFn, CountdownControllers, CountdownOptions, DOTS, DarkModeOptions, DarkModeReturn, DebouncedState, EventType, IntersectionReturn, MapOrEntries, Options, OriginalStyle, SetStepCallbackType, Size, TernaryDarkMode, TernaryDarkModeOptions, TernaryDarkModeReturn, UseAsyncState, UseBooleanReturn, UseCounterReturn, UseDebounceValueOptions, UseDocumentTitleOptions, UseIntersectionObserverOptions, UseIntersectionObserverState, UseListActions, UseListReturn, UseLocalStorageOptions, UseMapActions, UseMapReturn, UseMediaQueryOptions, UseResizeObserverOptions, UseScreenOptions, UseScriptOptions, UseScriptStatus, UseScrollLockOptions, UseScrollLockReturn, UseSessionStorageOptions, UseStepActions, UseWindowSizeOptions, WindowSize, useAsync, useBoolean, useClickAnyWhere, useCopyToClipboard, useCountdown, useCounter, useDarkMode, useDebounceCallback, useDebounceValue, useDisclosure, useDocumentTitle, useEventCallback, useEventListener, useGeolocation, useHover, useIdle, useIntersectionObserver, useInterval, useIsClient, useIsMounted, useIsomorphicLayoutEffect, useList, useLocalStorage, useMap, useMediaQuery, useMemoizedFn, useNetwork, useOnClickOutside, usePageLeave, usePagination, usePermission, usePrevious, useQueue, useReadLocalStorage, useResizeObserver, useScreen, useScript, useScrollLock, useSessionStorage, useSet, useStateList, useStep, useTernaryDarkMode, useThrottle, useThrottleFn, useTimeout, useToggle, useUnmount, useUpdate, useUpdateEffect, useWindowSize };
|