Skip to content

use-debounce

Compare
Choose a tag to compare
@xnimorz xnimorz released this 27 Feb 19:58
· 297 commits to master since this release

The full example: https://codesandbox.io/s/4wvmp1xlw4

  • add maxWait option. The maximum time func is allowed to be delayed before it's invoked.
  • add cancel callback (thanks to @thibaultboursier or contributing). Cancel callback removes func from the queue (even maxWait).
  • [BREAKING] change the contact of use-debounce callback and value hooks:

Old:

import { useDebounce, useDebouncedCallback } from 'use-debounce';

...
const debouncedValue = useDebounce(value, 1000);
const debouncedCallback = useDebouncedCallback(() => {...}, 1000);

New:

import { useDebounce, useDebouncedCallback } from 'use-debounce';

...
const [ debouncedValue, cancelValueDebouncingCycle ] = useDebounce(value, 1000);
const [ debouncedCallback, cancelCallback ] = useDebouncedCallback(() => {...}, 1000);

You still can use only value and callback:

import { useDebounce, useDebouncedCallback } from 'use-debounce';

...
const [ debouncedValue ] = useDebounce(value, 1000);
const [ debouncedCallback ] = useDebouncedCallback(() => {...}, 1000);