Skip to content
On this page

useTimeoutFn

Category
Export Size
347 B
Last Changed
3 weeks ago

Wrapper for setTimeout with controls.

Demo

Please wait for 3 seconds

Usage

js
import { useTimeoutFn } from '@vueuse/core'

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

const { isPending, start, stop } = useTimeoutFn(() => {
  /* ... */
}, 3000)

Type Declarations

typescript
export interface UseTimeoutFnOptions {
  /**
   * Start the timer immediate after calling this function
   *
   * @default true
   */
  immediate?: boolean
}
/**
 * Wrapper for `setTimeout` with controls.
 *
 * @param cb
 * @param interval
 * @param options
 */
export declare function useTimeoutFn<
  CallbackFn extends (...args: any[]) => any
>(
  cb: CallbackFn,
  interval: MaybeComputedRef<number>,
  options?: UseTimeoutFnOptions
): Stoppable<Parameters<CallbackFn> | []>
export interface UseTimeoutFnOptions {
  /**
   * Start the timer immediate after calling this function
   *
   * @default true
   */
  immediate?: boolean
}
/**
 * Wrapper for `setTimeout` with controls.
 *
 * @param cb
 * @param interval
 * @param options
 */
export declare function useTimeoutFn<
  CallbackFn extends (...args: any[]) => any
>(
  cb: CallbackFn,
  interval: MaybeComputedRef<number>,
  options?: UseTimeoutFnOptions
): Stoppable<Parameters<CallbackFn> | []>

Source

SourceDemoDocs

Contributors

Anthony Fu
Scott Bedard
Dan Rose
Kasper Seweryn
jack zhang
vaakian X
Jelf
Shinigami
Peter Shih
liaoliao666
Sergey Shumov

Changelog

v9.12.0 on 1/29/2023
39183 - feat(useRafFn, useIntervalFn, useTimeoutFn): make status readonly (#2685)
e054a - fix: respect callback parameters in start function (#2693)
v9.1.1 on 8/23/2022
0fdbb - fix(shared): resolve internal circular reference
v9.0.0-beta.1 on 7/20/2022
4ca70 - fix(useTimeoutFn,useTimeout)!: rename type TimeoutOptions to UseTimeoutOptions and TimeoutFnOptions to UseTimeoutFnOptions (#1944)
v8.9.1 on 7/8/2022
a9ccc - feat(all): use MaybeComputedRef (#1768)

Released under the MIT License.