Options
All
  • Public
  • Public/Protected
  • All
Menu

Module lib/hooks/useDelayCallback

Index

Functions

  • useDelayCallback<T>(callback: T, delay?: number, deps?: undefined | DependencyList, existing?: "prefer" | "cancel"): [callback: T, cancelFn: (() => void)]
  • Similar to useCallback but adds a delay so that the callback fires only after delay milliseconds.

    Type Parameters

    • T extends ((...args: any[]) => void)

    Parameters

    • callback: T

      Same as useCallback

    • delay: number = 0

      How long to delay calling callback in milliseconds

    • deps: undefined | DependencyList = undefined

      Same as useCallback

    • existing: "prefer" | "cancel" = 'cancel'

      Whether or not to cancel the existing callback or preserve it If set to cancel, any existing callback will be cancelled and the timer will reset, delaying the total time before it executes. If set to preserve, the existing callback is kept and the new call is ignored.

    Returns [callback: T, cancelFn: (() => void)]

    • [callbackFn, cancelFn] callbackFn - The function/handler to invoke which is now wrapped in setTimeout cancelFn - A function that can be used to manually cancel the timer

Generated using TypeDoc