TwitterGitHub
Dark LogoStratik / UIbeta
useDelay

The useDelay hook introduces a delay before executing a specified action, utilizing useTimeout and Promise for managing the delay. This hook supports both synchronous and asynchronous functions, making it versatile for various use cases where deferred actions are needed, such as enhancing user experience or managing timed events.

Options Table
NameTypeDefaultDescription
immediatebooleanfalseIf true, the callback will be executed immediately before the delay.
Return Table
NameTypeDescription
isDelayingbooleanIndicates whether the delay is currently active.
delay(time: number, callback?: () => void, options?: UseDelayOptions) => voidInitiates a delay for the specified time and optionally executes a callback.
clearDelay() => voidClears the current delay and stops the timer.

delay

NameTypeDefaultDescription
timenumber-The time in milliseconds for which to delay.
callback() => void-Optional function to execute after the delay is complete.
optionsUseDelayOptions{}Optional configuration for delay behavior (e.g., immediate execution).

Click to see the delayed action