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

Version Path
katello-4.15.0.rc2 webpack/utils/useDebounce.js
katello-4.15.0.rc1 webpack/utils/useDebounce.js
katello-4.14.1 webpack/utils/useDebounce.js
katello-4.14.0 webpack/utils/useDebounce.js
katello-4.14.0.rc3 webpack/utils/useDebounce.js
katello-4.14.0.rc2 webpack/utils/useDebounce.js
katello-4.14.0.rc1.1 webpack/utils/useDebounce.js
katello-4.14.0.rc1 webpack/utils/useDebounce.js
katello-4.13.1 webpack/utils/useDebounce.js
katello-4.13.0 webpack/utils/useDebounce.js
katello-4.12.1 webpack/utils/useDebounce.js
katello-4.13.0.rc1 webpack/utils/useDebounce.js
katello-4.12.0 webpack/utils/useDebounce.js
katello-4.12.0.rc3 webpack/utils/useDebounce.js
katello-4.12.0.rc2 webpack/utils/useDebounce.js
katello-4.12.0.rc1 webpack/utils/useDebounce.js
katello-4.11.1 webpack/utils/useDebounce.js
katello-4.11.0 webpack/utils/useDebounce.js
katello-4.11.0.rc2 webpack/utils/useDebounce.js
katello-4.11.0.rc1 webpack/utils/useDebounce.js