useDebounce

Debounce a value to prevent frequent updates.

https://www.shaktools.com/shak-hooks
Utility

API Reference

Installation

terminal
pnpm add @shak-hooks/usehooks
import.ts
import { useDebounce } from "@shak-hooks/usehooks";
Source: packages/react/src/useDebounce.ts

Signature

signature.ts
export function useDebounce<T>(value: T, delay: number): T

Parameters

NameTypeOptionalDefault
valueTNo-
delaynumberNo-

Returns

T

Implementation

use-debounce.ts
1import { useState, useEffect } from "react";
2
3export function useDebounce<T>(value: T, delay: number): T {
4 const [debouncedValue, setDebouncedValue] = useState<T>(value);
5
6 useEffect(() => {
7 const handler = setTimeout(() => {
8 setDebouncedValue(value);
9 }, delay);
10
11 return () => {
12 clearTimeout(handler);
13 };
14 }, [value, delay]);
15
16 return debouncedValue;
17}

Advertisement

Google Ads

Usage

example.tsx
1import { useDebounce } from "@shak-hooks/usehooks";
2
3const result = useDebounce(undefined, 0);
4// result: T
5// Use values directly (React state).

Let‘s do great work together

Empowering creators with free, high-performance AI, SEO, and developer tools. Join thousands of users optimizing their workflow with Shak-Tools.

Tools10+ Free
UsersGlobal

Stay in the loop

Join our newsletter for the latest AI tools and updates.

ShakTools
© 2025 Shaktools. All Rights Reserved.Privacy Policy