useDebounce Custom Hook

Custom Hooks — Intermediate React challenge.

Implement a custom hook that delays propagating a value until a given amount of time has passed without further changes. Useful for search inputs, autosave, and throttled event streams.

Requirements

Signature

function useDebounce<T>(value: T, delay?: number): T

Example

const [q, setQ] = useState("");
const debounced = useDebounce(q, 300);

Constraints

🏷️ Get 20% OFF on Yearly & Lifetime plans — use code 🏷️ Get 20% OFF on Yearly & Lifetime plans — use code 🏷️ Get 20% OFF on Yearly & Lifetime plans — use code 🏷️ Get 20% OFF on Yearly & Lifetime plans — use code 🏷️ Get 20% OFF on Yearly & Lifetime plans — use code 🏷️ Get 20% OFF on Yearly & Lifetime plans — use code
Loading workspace…