shelving
Version:
Toolkit for using data in JavaScript.
12 lines (11 loc) • 766 B
TypeScript
/**
* Set a state using a "debounce" delay — this ensures that the state is only updated after the specified delay has passed since the last update.
* - Useful for input fields where you want to wait until the user has stopped typing before performing an action (e.g., API call).
*/
export declare function useDebouncedState<T>(initial: T, delay?: number): [T, (v: T) => void];
/**
* Debounce a callback function — the callback will only be invoked after the specified delay has passed since the last call.
* - Useful for triggering form submissions after the user has stopped typing.
* - Automatically cleans up pending timeouts on unmount.
*/
export declare function useDebouncedCallback(callback: (() => void) | undefined, delay?: number): () => void;