Snippet is a personal snippet library powered by embeddings. Search by meaning, not keywords — even when you forgot what you named the file.
Defer a changing value until typing stops for N ms.
const useDebouncedValue = <T,>(value: T, delay = 300) => {
const [debounced, setDebounced] = useState(value);
useEffect(() => {
const id = setTimeout(() => setDebounced(value), delay);
return () => clearTimeout(id);
}, [value, delay]);
return debounced;
};