Skip to content

Releases: xnimorz/use-debounce

8.0.2

14 Jul 21:16
Compare
Choose a tag to compare

8.0.1

05 May 22:11
Compare
Choose a tag to compare

Added jest@28 support

8.0.0

01 May 21:35
Compare
Choose a tag to compare
  • breaking change useDebounce changed its build system to microbundle. For now we have several entries:

index.js is for commonJS approach
index.modern.js for esnext module system
index.umd.js for UMD.
All the files are in dist folder.

If you have any paths which have esm or lib, please, replace them to dist:

Before:

import useDebounceCallback from 'use-debounce/lib/useDebounceCallback'

After:

import { useDebounceCallback } from 'use-debounce';
  • Fixed issue with incorrect VSCode autocomplete #131 Thanks to @c-ehrlich for reporting
  • Fixed useDebounce behaviour with react-devtools tab when devtools have a component with useDebounce or useDebounceCallback opened. #129 Thanks to @alexniarchos for reporting
  • Fixed issue with leading: true #124 Thanks to @mntnoe for reporting

7.0.0 isPending is sync

20 Jun 15:16
ef6a4e5
Compare
Choose a tag to compare

6.0.1

03 Apr 14:40
Compare
Choose a tag to compare
  • Fixed useDebouncedCallback return type. Closed #103 thanks to @VanTanev

Clarifying API and major under hood improvements

07 Mar 20:53
ff1eb32
Compare
Choose a tag to compare
  • breakind change: removed callback field, instead of this useDebouncedCallback and useThrottledCallback returns a callable function:
    Old:

    const { callback, pending } = useDebouncedCallback(/*...*/);
    // ...
    debounced.callback();

    New:

    const debounced = useDebouncedCallback(/*...*/);
    // ...
    debounced();
    /**
     * Also debounced has fields:
     * {
     *   cancel: () => void
     *   flush: () => void
     *   isPending: () => boolean
     * }
     * So you can call debounced.cancel(), debounced.flush(), debounced.isPending()
     */

    It makes easier to understand which cancel \ flush or isPending is called in case you have several debounced functions in your component

  • breaking change: Now useDebounce, useDebouncedCallback and useThrottledCallback has isPending method instead of pending

    Old:

    const { callback, pending } = useDebouncedCallback(/*...*/);

    New:

    const { callback, isPending } = useDebouncedCallback(/*...*/);
    /**
     * {
     *   callback: (...args: any[]) => ReturnType<T>
     *   cancel: () => void
     *   flush: () => void
     *   isPending: () => boolean
     * }
     */
  • get rid of useCallback calls

  • improve internal typing

  • decrease the amount of functions to initialize each useDebouncedCallback call

  • reduce library size:

    Whole library: from 946 B to 899 B === 47 B
    useDebounce: from 844 to 791 === 53 B
    useDebouncedCallback: from 680 to 623 === 57 B
    useThrottledCallback: from 736 to 680 === 56 B

Unmounted components fix

20 Feb 17:05
e1ccfb2
Compare
Choose a tag to compare
  • prevent having ininite setTimeout setup when component gets unmounted #97
  • function type works correctly with useDebounce now. #95 Thanks to @csu-feizao

useThrottledCallback

11 Dec 23:32
Compare
Choose a tag to compare
  • Added useThrottledCallback

5.0.1

29 Sep 09:07
Compare
Choose a tag to compare
  • Fix typing to infer correct callback type (thanks to @lytc)

5.0.0

19 Sep 10:11
Compare
Choose a tag to compare
  • breaking change: Now useDebouncedCallback returns an object instead of array:

    Old:

    const [debouncedCallback, cancelDebouncedCallback, callPending] = useDebouncedCallback(/*...*/);

    New:

    const debounced = useDebouncedCallback(/*...*/);
    /**
     * debounced: {
     *   callback: (...args: T) => unknown, which is debouncedCallback
     *   cancel: () => void, which is cancelDebouncedCallback
     *   flush: () => void, which is callPending
     *   pending: () => boolean, which is a new function
     * } 
     */
  • breaking change: Now useDebounce returns an array of 2 fields instead of a plain array:
    Old:

    const [value, cancel, callPending] = useDebounce(/*...*/);

    New:

    const [value, fn] = useDebouncedCallback(/*...*/);
    /**
     * value is just a value without changes
     * But fn now is an object: { 
     *   cancel: () => void, which is cancel
     *   flush: () => void, which is callPending
     *   pending: () => boolean, which is a new function
     * } 
     */
  • Added pending function to both useDebounce and useDebouncedCallback which shows whether component has pending callbacks
    Example:

    function Component({ text }) {
      const debounced = useDebouncedCallback(useCallback(() => {}, []), 500);
    
      expect(debounced.pending()).toBeFalsy();
      debounced.callback();
      expect(debounced.pending()).toBeTruthy();
      debounced.flush();
      expect(debounced.pending()).toBeFalsy();
    
      return <span>{text}</span>;
    }

For more details of these major changes you could check this commit 1b4ac04 and this issue #61

  • Fixed security alerts