Skip to content

Commit fec4384

Browse files
committed
docs: Clean up comments for clarity
1 parent 913f944 commit fec4384

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

site/src/hooks/debounce.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,22 +17,18 @@ type useDebouncedFunctionReturn<Args extends unknown[]> = Readonly<{
1717
*
1818
* If the debounce time changes while a callback has been queued to fire, the
1919
* callback will be canceled completely. You will need to restart the debounce
20-
* process by calling debounced again.
20+
* process by calling the returned-out function again.
2121
*/
2222
export function useDebouncedFunction<
2323
// Parameterizing on the args instead of the whole callback function type to
24-
// avoid type contra-variance issues; want to avoid need for type assertions
24+
// avoid type contra-variance issues
2525
Args extends unknown[] = unknown[],
2626
>(
2727
callback: (...args: Args) => void | Promise<void>,
2828
debounceTimeMs: number,
2929
): useDebouncedFunctionReturn<Args> {
3030
const timeoutIdRef = useRef<number | null>(null);
3131
const cancelDebounce = useCallback(() => {
32-
// Clearing timeout because, even though hot-swapping the timeout value
33-
// while keeping any active debounced functions running was possible, it
34-
// seemed like it'd be ripe for bugs. Can redesign the logic if that ends up
35-
// becoming an actual need down the line.
3632
if (timeoutIdRef.current !== null) {
3733
window.clearTimeout(timeoutIdRef.current);
3834
}
@@ -69,6 +65,9 @@ export function useDebouncedFunction<
6965
return { debounced, cancelDebounce } as const;
7066
}
7167

68+
/**
69+
* Takes any value, and returns out a debounced version of it.
70+
*/
7271
export function useDebouncedValue<T = unknown>(
7372
value: T,
7473
debounceTimeMs: number,

0 commit comments

Comments
 (0)