react-hook-toolkit 4.0.0 → 5.0.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/README.md +289 -36
- package/dist/chunk1516/chunk1617.d.ts +190 -0
- package/dist/chunk1516/chunk1617.js +408 -0
- package/dist/chunk1516/chunk1718.d.ts +324 -0
- package/dist/chunk1516/chunk1718.js +783 -0
- package/dist/chunk1516/chunk1819.d.ts +90 -0
- package/dist/chunk1516/chunk1819.js +235 -0
- package/dist/chunk1516/chunk1920.d.ts +104 -0
- package/dist/chunk1516/chunk1920.js +274 -0
- package/dist/chunk1516/chunk2021.d.ts +219 -0
- package/dist/chunk1516/chunk2021.js +406 -0
- package/dist/chunk1516/chunk2122.d.ts +77 -0
- package/dist/chunk1516/chunk2122.js +193 -0
- package/dist/index.d.ts +7 -1
- package/dist/index.js +7 -1
- package/package.json +1 -1
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { DependencyList } from 'react';
|
|
2
|
+
/**
|
|
3
|
+
* Like useState but fires a callback after the state update has been applied
|
|
4
|
+
* and the component has re-rendered (via useEffect).
|
|
5
|
+
*/
|
|
6
|
+
export declare function useStateWithCallback<T>(initialValue: T): [T, (value: T, callback?: (v: T) => void) => void];
|
|
7
|
+
/**
|
|
8
|
+
* Like useState for objects but merges partial updates (à la class component setState).
|
|
9
|
+
* Only call with object types.
|
|
10
|
+
*/
|
|
11
|
+
export declare function useMergeState<T extends Record<string, any>>(initialState: T): [T, (patch: Partial<T>) => void, () => void];
|
|
12
|
+
/**
|
|
13
|
+
* useState augmented with a reset() function that returns the state to its
|
|
14
|
+
* initial value without needing to hold a reference to that value.
|
|
15
|
+
*/
|
|
16
|
+
export declare function useResetState<T>(initialValue: T): [T, React.Dispatch<React.SetStateAction<T>>, () => void];
|
|
17
|
+
/**
|
|
18
|
+
* State that stays in sync across browser tabs/windows via the BroadcastChannel API.
|
|
19
|
+
* Falls back to a regular useState when BroadcastChannel is unavailable.
|
|
20
|
+
*/
|
|
21
|
+
export declare function useSyncedState<T>(channel: string, initialValue: T): [T, (value: T) => void];
|
|
22
|
+
/**
|
|
23
|
+
* Derives a value from a source value using a transform function.
|
|
24
|
+
* Re-computes only when the source changes (same as useMemo but with a
|
|
25
|
+
* clearer "derive from source" intent).
|
|
26
|
+
*/
|
|
27
|
+
export declare function useDerivedState<S, T>(source: S, transform: (source: S) => T, deps?: DependencyList): T;
|
|
28
|
+
/**
|
|
29
|
+
* State with a patch() method that does a deep-partial update (one level).
|
|
30
|
+
* Useful for updating nested config/settings objects.
|
|
31
|
+
*/
|
|
32
|
+
export declare function usePatch<T extends Record<string, any>>(initialState: T): {
|
|
33
|
+
state: T;
|
|
34
|
+
patch: (partial: Partial<T>) => void;
|
|
35
|
+
set: React.Dispatch<React.SetStateAction<T>>;
|
|
36
|
+
reset: () => void;
|
|
37
|
+
};
|
|
38
|
+
/**
|
|
39
|
+
* Evaluates an initializer function exactly once (on mount) and returns the
|
|
40
|
+
* result for the lifetime of the component. Unlike useMemo, this is guaranteed
|
|
41
|
+
* never to be re-computed.
|
|
42
|
+
*/
|
|
43
|
+
export declare function useConstant<T>(init: () => T): T;
|
|
44
|
+
/**
|
|
45
|
+
* Memoizes a computed value with explicit dependencies.
|
|
46
|
+
* A semantic alias for useMemo that makes the "compute" intent clearer.
|
|
47
|
+
*/
|
|
48
|
+
export declare function useComputed<T>(compute: () => T, deps: DependencyList): T;
|
|
49
|
+
/**
|
|
50
|
+
* Returns a stable function reference that always delegates to the latest
|
|
51
|
+
* version of the provided callback. A semantic alias for useEventCallback —
|
|
52
|
+
* safe to pass to event listeners without causing re-subscriptions.
|
|
53
|
+
*/
|
|
54
|
+
export declare function useStableCallback<T extends (...args: any[]) => any>(fn: T): T;
|
|
55
|
+
/**
|
|
56
|
+
* Returns the number of times the component has rendered.
|
|
57
|
+
* Starts at 1 (the initial render). Useful for debugging performance.
|
|
58
|
+
*/
|
|
59
|
+
export declare function useRenderCount(): number;
|
|
60
|
+
/**
|
|
61
|
+
* Like useEffect but uses deep equality to compare deps instead of reference equality.
|
|
62
|
+
* Prevents spurious re-runs when object/array deps are recreated with the same values.
|
|
63
|
+
*/
|
|
64
|
+
export declare function useDeepCompareEffect(effect: React.EffectCallback, deps: DependencyList): void;
|
|
65
|
+
/**
|
|
66
|
+
* Like useMemo but uses deep equality to compare deps.
|
|
67
|
+
*/
|
|
68
|
+
export declare function useDeepCompareMemo<T>(factory: () => T, deps: DependencyList): T;
|
|
69
|
+
/**
|
|
70
|
+
* Returns true when the value is shallowly equal to the previous render's value.
|
|
71
|
+
* Returns the previous (stable) reference when equal so downstream memos don't break.
|
|
72
|
+
*/
|
|
73
|
+
export declare function useShallowEqual<T>(value: T): T;
|
|
74
|
+
interface UseErrorBoundaryReturn {
|
|
75
|
+
error: Error | null;
|
|
76
|
+
resetError: () => void;
|
|
77
|
+
showBoundary: (error: Error) => void;
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Imperative error-boundary hook. Call showBoundary(error) to surface an error
|
|
81
|
+
* to the nearest React error boundary. Call resetError() to clear it.
|
|
82
|
+
* Pair with an <ErrorBoundary> component in the tree.
|
|
83
|
+
*/
|
|
84
|
+
export declare function useErrorBoundary(): UseErrorBoundaryReturn;
|
|
85
|
+
/**
|
|
86
|
+
* Wraps useReducer to log every dispatched action and resulting state to the
|
|
87
|
+
* console in development mode. Zero overhead in production.
|
|
88
|
+
*/
|
|
89
|
+
export declare function useReducerLogger<S, A>(reducer: React.Reducer<S, A>, initialState: S): [S, React.Dispatch<A>];
|
|
90
|
+
export {};
|
|
@@ -0,0 +1,235 @@
|
|
|
1
|
+
import { useState, useEffect, useCallback, useRef, useMemo, useReducer } from 'react';
|
|
2
|
+
// ─── useStateWithCallback ─────────────────────────────────────────────────────
|
|
3
|
+
/**
|
|
4
|
+
* Like useState but fires a callback after the state update has been applied
|
|
5
|
+
* and the component has re-rendered (via useEffect).
|
|
6
|
+
*/
|
|
7
|
+
export function useStateWithCallback(initialValue) {
|
|
8
|
+
const [state, setState] = useState(initialValue);
|
|
9
|
+
const callbackRef = useRef(null);
|
|
10
|
+
const setStateWithCallback = useCallback((value, callback) => {
|
|
11
|
+
callbackRef.current = callback !== null && callback !== void 0 ? callback : null;
|
|
12
|
+
setState(value);
|
|
13
|
+
}, []);
|
|
14
|
+
useEffect(() => {
|
|
15
|
+
if (callbackRef.current) {
|
|
16
|
+
callbackRef.current(state);
|
|
17
|
+
callbackRef.current = null;
|
|
18
|
+
}
|
|
19
|
+
}, [state]);
|
|
20
|
+
return [state, setStateWithCallback];
|
|
21
|
+
}
|
|
22
|
+
// ─── useMergeState ────────────────────────────────────────────────────────────
|
|
23
|
+
/**
|
|
24
|
+
* Like useState for objects but merges partial updates (à la class component setState).
|
|
25
|
+
* Only call with object types.
|
|
26
|
+
*/
|
|
27
|
+
export function useMergeState(initialState) {
|
|
28
|
+
const [state, setState] = useState(initialState);
|
|
29
|
+
const merge = useCallback((patch) => {
|
|
30
|
+
setState(prev => (Object.assign(Object.assign({}, prev), patch)));
|
|
31
|
+
}, []);
|
|
32
|
+
const reset = useCallback(() => setState(initialState), []);
|
|
33
|
+
return [state, merge, reset];
|
|
34
|
+
}
|
|
35
|
+
// ─── useResetState ────────────────────────────────────────────────────────────
|
|
36
|
+
/**
|
|
37
|
+
* useState augmented with a reset() function that returns the state to its
|
|
38
|
+
* initial value without needing to hold a reference to that value.
|
|
39
|
+
*/
|
|
40
|
+
export function useResetState(initialValue) {
|
|
41
|
+
const initial = useRef(initialValue);
|
|
42
|
+
const [state, setState] = useState(initialValue);
|
|
43
|
+
const reset = useCallback(() => setState(initial.current), []);
|
|
44
|
+
return [state, setState, reset];
|
|
45
|
+
}
|
|
46
|
+
// ─── useSyncedState ───────────────────────────────────────────────────────────
|
|
47
|
+
/**
|
|
48
|
+
* State that stays in sync across browser tabs/windows via the BroadcastChannel API.
|
|
49
|
+
* Falls back to a regular useState when BroadcastChannel is unavailable.
|
|
50
|
+
*/
|
|
51
|
+
export function useSyncedState(channel, initialValue) {
|
|
52
|
+
const [state, setState] = useState(initialValue);
|
|
53
|
+
const channelRef = useRef(null);
|
|
54
|
+
useEffect(() => {
|
|
55
|
+
if (typeof BroadcastChannel === 'undefined')
|
|
56
|
+
return;
|
|
57
|
+
const bc = new BroadcastChannel(channel);
|
|
58
|
+
channelRef.current = bc;
|
|
59
|
+
bc.onmessage = (e) => setState(e.data);
|
|
60
|
+
return () => bc.close();
|
|
61
|
+
}, [channel]);
|
|
62
|
+
const set = useCallback((value) => {
|
|
63
|
+
var _a;
|
|
64
|
+
setState(value);
|
|
65
|
+
(_a = channelRef.current) === null || _a === void 0 ? void 0 : _a.postMessage(value);
|
|
66
|
+
}, []);
|
|
67
|
+
return [state, set];
|
|
68
|
+
}
|
|
69
|
+
// ─── useDerivedState ──────────────────────────────────────────────────────────
|
|
70
|
+
/**
|
|
71
|
+
* Derives a value from a source value using a transform function.
|
|
72
|
+
* Re-computes only when the source changes (same as useMemo but with a
|
|
73
|
+
* clearer "derive from source" intent).
|
|
74
|
+
*/
|
|
75
|
+
export function useDerivedState(source, transform, deps) {
|
|
76
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
77
|
+
return useMemo(() => transform(source), deps !== null && deps !== void 0 ? deps : [source]);
|
|
78
|
+
}
|
|
79
|
+
// ─── usePatch ─────────────────────────────────────────────────────────────────
|
|
80
|
+
/**
|
|
81
|
+
* State with a patch() method that does a deep-partial update (one level).
|
|
82
|
+
* Useful for updating nested config/settings objects.
|
|
83
|
+
*/
|
|
84
|
+
export function usePatch(initialState) {
|
|
85
|
+
const initial = useRef(initialState);
|
|
86
|
+
const [state, set] = useState(initialState);
|
|
87
|
+
const patch = useCallback((partial) => set(prev => (Object.assign(Object.assign({}, prev), partial))), []);
|
|
88
|
+
const reset = useCallback(() => set(initial.current), []);
|
|
89
|
+
return { state, patch, set, reset };
|
|
90
|
+
}
|
|
91
|
+
// ─── useConstant ──────────────────────────────────────────────────────────────
|
|
92
|
+
/**
|
|
93
|
+
* Evaluates an initializer function exactly once (on mount) and returns the
|
|
94
|
+
* result for the lifetime of the component. Unlike useMemo, this is guaranteed
|
|
95
|
+
* never to be re-computed.
|
|
96
|
+
*/
|
|
97
|
+
export function useConstant(init) {
|
|
98
|
+
const ref = useRef(null);
|
|
99
|
+
if (ref.current === null) {
|
|
100
|
+
ref.current = { value: init() };
|
|
101
|
+
}
|
|
102
|
+
return ref.current.value;
|
|
103
|
+
}
|
|
104
|
+
// ─── useComputed ──────────────────────────────────────────────────────────────
|
|
105
|
+
/**
|
|
106
|
+
* Memoizes a computed value with explicit dependencies.
|
|
107
|
+
* A semantic alias for useMemo that makes the "compute" intent clearer.
|
|
108
|
+
*/
|
|
109
|
+
export function useComputed(compute, deps) {
|
|
110
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
111
|
+
return useMemo(compute, deps);
|
|
112
|
+
}
|
|
113
|
+
// ─── useStableCallback ────────────────────────────────────────────────────────
|
|
114
|
+
/**
|
|
115
|
+
* Returns a stable function reference that always delegates to the latest
|
|
116
|
+
* version of the provided callback. A semantic alias for useEventCallback —
|
|
117
|
+
* safe to pass to event listeners without causing re-subscriptions.
|
|
118
|
+
*/
|
|
119
|
+
export function useStableCallback(fn) {
|
|
120
|
+
const ref = useRef(fn);
|
|
121
|
+
useEffect(() => { ref.current = fn; });
|
|
122
|
+
return useCallback((...args) => ref.current(...args), []);
|
|
123
|
+
}
|
|
124
|
+
// ─── useRenderCount ───────────────────────────────────────────────────────────
|
|
125
|
+
/**
|
|
126
|
+
* Returns the number of times the component has rendered.
|
|
127
|
+
* Starts at 1 (the initial render). Useful for debugging performance.
|
|
128
|
+
*/
|
|
129
|
+
export function useRenderCount() {
|
|
130
|
+
const count = useRef(0);
|
|
131
|
+
count.current += 1;
|
|
132
|
+
return count.current;
|
|
133
|
+
}
|
|
134
|
+
// ─── useDeepCompare ───────────────────────────────────────────────────────────
|
|
135
|
+
function deepEqual(a, b) {
|
|
136
|
+
if (a === b)
|
|
137
|
+
return true;
|
|
138
|
+
if (typeof a !== typeof b)
|
|
139
|
+
return false;
|
|
140
|
+
if (a === null || b === null)
|
|
141
|
+
return a === b;
|
|
142
|
+
if (Array.isArray(a) && Array.isArray(b)) {
|
|
143
|
+
if (a.length !== b.length)
|
|
144
|
+
return false;
|
|
145
|
+
return a.every((v, i) => deepEqual(v, b[i]));
|
|
146
|
+
}
|
|
147
|
+
if (typeof a === 'object') {
|
|
148
|
+
const keysA = Object.keys(a);
|
|
149
|
+
const keysB = Object.keys(b);
|
|
150
|
+
if (keysA.length !== keysB.length)
|
|
151
|
+
return false;
|
|
152
|
+
return keysA.every(k => deepEqual(a[k], b[k]));
|
|
153
|
+
}
|
|
154
|
+
return false;
|
|
155
|
+
}
|
|
156
|
+
/**
|
|
157
|
+
* Like useEffect but uses deep equality to compare deps instead of reference equality.
|
|
158
|
+
* Prevents spurious re-runs when object/array deps are recreated with the same values.
|
|
159
|
+
*/
|
|
160
|
+
export function useDeepCompareEffect(effect, deps) {
|
|
161
|
+
const ref = useRef(undefined);
|
|
162
|
+
if (!deepEqual(ref.current, deps)) {
|
|
163
|
+
ref.current = deps;
|
|
164
|
+
}
|
|
165
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
166
|
+
useEffect(effect, [ref.current]);
|
|
167
|
+
}
|
|
168
|
+
/**
|
|
169
|
+
* Like useMemo but uses deep equality to compare deps.
|
|
170
|
+
*/
|
|
171
|
+
export function useDeepCompareMemo(factory, deps) {
|
|
172
|
+
const ref = useRef(undefined);
|
|
173
|
+
if (!deepEqual(ref.current, deps)) {
|
|
174
|
+
ref.current = deps;
|
|
175
|
+
}
|
|
176
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
177
|
+
return useMemo(factory, [ref.current]);
|
|
178
|
+
}
|
|
179
|
+
// ─── useShallowEqual ──────────────────────────────────────────────────────────
|
|
180
|
+
function shallowEqual(a, b) {
|
|
181
|
+
if (a === b)
|
|
182
|
+
return true;
|
|
183
|
+
if (typeof a !== 'object' || typeof b !== 'object')
|
|
184
|
+
return false;
|
|
185
|
+
if (a === null || b === null)
|
|
186
|
+
return false;
|
|
187
|
+
const keysA = Object.keys(a);
|
|
188
|
+
const keysB = Object.keys(b);
|
|
189
|
+
if (keysA.length !== keysB.length)
|
|
190
|
+
return false;
|
|
191
|
+
return keysA.every(k => a[k] === b[k]);
|
|
192
|
+
}
|
|
193
|
+
/**
|
|
194
|
+
* Returns true when the value is shallowly equal to the previous render's value.
|
|
195
|
+
* Returns the previous (stable) reference when equal so downstream memos don't break.
|
|
196
|
+
*/
|
|
197
|
+
export function useShallowEqual(value) {
|
|
198
|
+
const ref = useRef(value);
|
|
199
|
+
if (!shallowEqual(ref.current, value)) {
|
|
200
|
+
ref.current = value;
|
|
201
|
+
}
|
|
202
|
+
return ref.current;
|
|
203
|
+
}
|
|
204
|
+
/**
|
|
205
|
+
* Imperative error-boundary hook. Call showBoundary(error) to surface an error
|
|
206
|
+
* to the nearest React error boundary. Call resetError() to clear it.
|
|
207
|
+
* Pair with an <ErrorBoundary> component in the tree.
|
|
208
|
+
*/
|
|
209
|
+
export function useErrorBoundary() {
|
|
210
|
+
const [error, setError] = useState(null);
|
|
211
|
+
// Re-throw during render so the nearest ErrorBoundary catches it
|
|
212
|
+
if (error)
|
|
213
|
+
throw error;
|
|
214
|
+
const showBoundary = useCallback((err) => setError(err), []);
|
|
215
|
+
const resetError = useCallback(() => setError(null), []);
|
|
216
|
+
return { error, resetError, showBoundary };
|
|
217
|
+
}
|
|
218
|
+
// ─── useReducerLogger ─────────────────────────────────────────────────────────
|
|
219
|
+
/**
|
|
220
|
+
* Wraps useReducer to log every dispatched action and resulting state to the
|
|
221
|
+
* console in development mode. Zero overhead in production.
|
|
222
|
+
*/
|
|
223
|
+
export function useReducerLogger(reducer, initialState) {
|
|
224
|
+
const wrappedReducer = useCallback((state, action) => {
|
|
225
|
+
const nextState = reducer(state, action);
|
|
226
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
227
|
+
console.groupCollapsed(`[useReducerLogger] action:`, action);
|
|
228
|
+
console.log('prev state:', state);
|
|
229
|
+
console.log('next state:', nextState);
|
|
230
|
+
console.groupEnd();
|
|
231
|
+
}
|
|
232
|
+
return nextState;
|
|
233
|
+
}, [reducer]);
|
|
234
|
+
return useReducer(wrappedReducer, initialState);
|
|
235
|
+
}
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
interface UsePaginationOptions {
|
|
2
|
+
total: number;
|
|
3
|
+
pageSize?: number;
|
|
4
|
+
initialPage?: number;
|
|
5
|
+
}
|
|
6
|
+
interface UsePaginationReturn {
|
|
7
|
+
page: number;
|
|
8
|
+
pageSize: number;
|
|
9
|
+
totalPages: number;
|
|
10
|
+
offset: number;
|
|
11
|
+
isFirstPage: boolean;
|
|
12
|
+
isLastPage: boolean;
|
|
13
|
+
next: () => void;
|
|
14
|
+
prev: () => void;
|
|
15
|
+
goTo: (page: number) => void;
|
|
16
|
+
setPageSize: (size: number) => void;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Manages client-side pagination state: current page, page size, total pages,
|
|
20
|
+
* and navigation helpers.
|
|
21
|
+
*/
|
|
22
|
+
export declare function usePagination(options: UsePaginationOptions): UsePaginationReturn;
|
|
23
|
+
interface UsePollingOptions {
|
|
24
|
+
interval?: number;
|
|
25
|
+
immediate?: boolean;
|
|
26
|
+
enabled?: boolean;
|
|
27
|
+
}
|
|
28
|
+
interface UsePollingReturn<T> {
|
|
29
|
+
data: T | null;
|
|
30
|
+
error: Error | null;
|
|
31
|
+
loading: boolean;
|
|
32
|
+
start: () => void;
|
|
33
|
+
stop: () => void;
|
|
34
|
+
isPolling: boolean;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Repeatedly calls an async function on a fixed interval.
|
|
38
|
+
* Returns the latest data/error and start/stop controls.
|
|
39
|
+
*/
|
|
40
|
+
export declare function usePolling<T>(fetcher: () => Promise<T>, options?: UsePollingOptions): UsePollingReturn<T>;
|
|
41
|
+
interface UseAbortFetchReturn<T> {
|
|
42
|
+
data: T | null;
|
|
43
|
+
error: Error | null;
|
|
44
|
+
loading: boolean;
|
|
45
|
+
abort: () => void;
|
|
46
|
+
refetch: () => void;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Fetches a URL with an AbortController so in-flight requests are automatically
|
|
50
|
+
* cancelled on unmount or when the URL changes.
|
|
51
|
+
*/
|
|
52
|
+
export declare function useAbortFetch<T>(url: string, options?: RequestInit): UseAbortFetchReturn<T>;
|
|
53
|
+
interface UseLazyFetchReturn<T> {
|
|
54
|
+
data: T | null;
|
|
55
|
+
error: Error | null;
|
|
56
|
+
loading: boolean;
|
|
57
|
+
fetch: (url: string, options?: RequestInit) => Promise<void>;
|
|
58
|
+
reset: () => void;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* A fetch hook that does NOT run on mount. Call the returned fetch() function
|
|
62
|
+
* to trigger a request imperatively (e.g. on button click).
|
|
63
|
+
*/
|
|
64
|
+
export declare function useLazyFetch<T>(): UseLazyFetchReturn<T>;
|
|
65
|
+
interface UseOptimisticUpdateReturn<T> {
|
|
66
|
+
data: T;
|
|
67
|
+
isPending: boolean;
|
|
68
|
+
error: Error | null;
|
|
69
|
+
update: (optimisticValue: T, action: () => Promise<T>) => Promise<void>;
|
|
70
|
+
rollback: () => void;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Applies an optimistic value immediately while an async action runs.
|
|
74
|
+
* Rolls back to the previous value on error.
|
|
75
|
+
*/
|
|
76
|
+
export declare function useOptimisticUpdate<T>(initialData: T): UseOptimisticUpdateReturn<T>;
|
|
77
|
+
interface UseStopwatchReturn {
|
|
78
|
+
elapsedMs: number;
|
|
79
|
+
isRunning: boolean;
|
|
80
|
+
start: () => void;
|
|
81
|
+
stop: () => void;
|
|
82
|
+
reset: () => void;
|
|
83
|
+
lap: () => number;
|
|
84
|
+
laps: number[];
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* A stopwatch that tracks elapsed milliseconds with start/stop/reset/lap controls.
|
|
88
|
+
*/
|
|
89
|
+
export declare function useStopwatch(): UseStopwatchReturn;
|
|
90
|
+
interface UseIdleCallbackOptions {
|
|
91
|
+
timeout?: number;
|
|
92
|
+
immediate?: boolean;
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Schedules a callback with requestIdleCallback, falling back to setTimeout
|
|
96
|
+
* in environments that don't support it (e.g. Safari).
|
|
97
|
+
*/
|
|
98
|
+
export declare function useIdleCallback(callback: () => void, options?: UseIdleCallbackOptions): void;
|
|
99
|
+
/**
|
|
100
|
+
* useEffect wrapper that accepts an async function and handles cleanup safely.
|
|
101
|
+
* The async function receives an isCancelled() check to guard async operations.
|
|
102
|
+
*/
|
|
103
|
+
export declare function useAsyncEffect(effect: (isCancelled: () => boolean) => Promise<void | (() => void)>, deps?: React.DependencyList): void;
|
|
104
|
+
export {};
|