useDebounceFun
A custom hook that debounces a function.
Installation
pnpm dlx shadcn@latest add https://reactusekit.dev/r/use-debounce-fun.json
Usage
import { useDebounceFun } from "@/hooks/use-debounce-fun";
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 |