useTimeout

A React Hook that create a state that changes after a specified delay.

Demo

Try to click the check button quickly in two seonds and after two seconds, or reset timeout and do it again.

Source
isTimeout:
false
isTimeout:
false

Usage

See API for more details.

Source

Click links below to view source on GitHub.

API

const isTimeout = useTimeout(2000) const { isTimeout, start, pause, reset } = useTimeout(2000, { controls: true })

Interval

A number that represents the delay in milliseconds.

Options

export interface UseTimeoutOptions<Controls extends boolean, Callback extends AnyFunc = AnyFunc> extends UseTimeoutFnOptions { /** * Expose more controls * * @defaultValue false */ controls?: Controls /** * Callback on timeout */ callback?: Callback }

Returns

export type UseTimeoutReturns<Controls extends boolean, C extends AnyFunc = AnyFunc> = Controls extends true ? Pausable<[], Parameters<C> | []> & { /** * Timeout state */ isTimeout: boolean /** * Reset the timeout */ reset(): void } : boolean