Sha256: 5eae48efca46c34d4ad41855dedb202665879d0b602820ff864a91ca837b8271
Contents?: true
Size: 583 Bytes
Versions: 70
Compression:
Stored size: 583 Bytes
Contents
import { useEffect, useState } from 'react'; export default (value, delay = 500) => { const [debouncedValue, setDebouncedValue] = useState(value); useEffect(() => { // If the value is undefined or "" we want any logic to update immediately // as we wouldn't be waiting on the user to finish typing any longer. if (!value) { setDebouncedValue(value); return () => undefined; } const timer = setTimeout(() => setDebouncedValue(value), delay); return () => { clearTimeout(timer); }; }, [value, delay]); return debouncedValue; };
Version data entries
70 entries across 70 versions & 1 rubygems