Skip to content

useTimeoutFn

Category
Export Size
297 B
Last Changed
5 days ago

Wrapper for setTimeout with controls

Demo

Usage

tsx
import { 
useTimeoutFn
} from '@reause/shared'
const {
isPending
,
start
,
stop
} =
useTimeoutFn
(() => {
/* ... */ }, 3000)

Type Declarations

ts
export interface UseTimeoutFnOptions {
    immediate?: boolean;
    immediateCallback?: boolean;
}

export interface UseTimeoutFnReturn<CallbackFn extends AnyFn> {
    isPending: boolean;
    stop: () => void;
    start: (...args: Parameters<CallbackFn> | [
    ]) => void;
}

type AnyFn = (...args: any[]) => any

export function useTimeoutFn<CallbackFn extends AnyFn>(cb: CallbackFn, interval: number, options?: UseTimeoutFnOptions): UseTimeoutFnReturn<CallbackFn>

Source

Source · Demo · VueUse

Contributors

hairyf

Changelog

v0.1.0 on
c0dc0 - fix(shared): resolve useTimeoutFn audit findings (#750)
30916 - fix(test): stabilize flaky timing-sensitive browser tests
8fddc - chore!: remove all Vue-only Maybe* types and getter unions, adopt React Ref (#462)

Released under the MIT License. v0.1.8