yarn use-debounce 5.0.0

latest releases: 10.0.0, 10.0.0-alpha, 9.0.4...
3 years ago
  • 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

Don't miss a new use-debounce release

NewReleases is sending notifications on new releases.