typescriptReactintermediate

React useDebounce Custom Hook

Generic debounce hook with cleanup timer in TypeScript

By ApeType Staff·16 lines·337 characters·1,420 total attempts
SOURCE CODE·typescript
import { useState, useEffect } from "react"; export function useDebounce<T>(value: T, delayMs: number): T { const [debouncedValue, setDebouncedValue] = useState<T>(value); useEffect(() => { const handler = setTimeout(() => { setDebouncedValue(value); }, delayMs); return () => { clearTimeout(handler); }; }, [value, delayMs]); return debouncedValue; }
UTF-8 · Tab indentationStandard Strict Parsing
TRANSCRIBE

Ready when you are.

Test your muscle memory and transcription speed against this exact snippet.

Start Typing
Tip: Press Esc anytime to restart

Best runs on this snippet

#TypistAccWPM
1Abel Gideon97.58%64
2Mishaal96.15%60
3Mishaal96.15%60
4Mishaal96.1%59
5Mishaal96.1%59