useDebounceFn

React hooks that debounce function.

Usage

import { useDebounceFn } from "@reactuses/core";

const Demo = () => {
  const [value, setValue] = useState(0);
  const { run } = useDebounceFn(() => {
    setValue(value + 1);
  }, 500);

  return (
    <div>
      <p style={{ marginTop: 16 }}> Clicked count: {value} </p>
      <button type="button" onClick={run}>
        Click fast!
      </button>
    </div>
  );
};

Example

Clicked count: 0

Type Declarations

/// <reference types="lodash" />
export default function useDebounceFn<T extends (...args: any) => any>(
  fn: T,
  wait?: number,
  options?: DebounceSettings
): {
  run: DebouncedFunc<(...args_0: Parameters<T>) => ReturnType<T>>
  cancel: () => void
  flush: () => ReturnType<T> | undefined
}