useDebounceFun
A custom hook that debounces a function.
Installation
npx react-usekit@latest init
Select: hooks → TypeScript or JavaScript → path -> useDebounceFun
Usage
import { useDebounceFun } from "./hooks/useDebounceFun";
function App() {
const handleSearch = (query: string) => {
console.log("Searching for:", query);
};
const debouncedSearch = useDebounceFun(handleSearch, 500);
return (
<div>
<input
type="text"
placeholder="Search..."
onChange={(e) => debouncedSearch(e.target.value)}
/>
</div>
);
}
API
Parameters
Parameter | Type | Description |
---|---|---|
func | (...args: any[]) => void | The function to debounce |
delay | number | The debounce delay in milliseconds |
Returns
Name | Type | Description |
---|---|---|
debouncedFunction | T | A debounced version of the function |