Skip to content
On this page

Demo

Category
Export Size
347 B
Last Changed
4 months ago

Please wait for 3 seconds

useTimeoutFn

Wrapper for setTimeout with controls.

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(
  cb: (...args: unknown[]) => any,
  interval: MaybeComputedRef<number>,
  options?: UseTimeoutFnOptions
): Stoppable
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(
  cb: (...args: unknown[]) => any,
  interval: MaybeComputedRef<number>,
  options?: UseTimeoutFnOptions
): Stoppable

Source

SourceDemoDocs

Contributors

Anthony Fu
Scott Bedard
vaakian X
Jelf
Shinigami
Peter Shih
liaoliao666
Sergey Shumov

Changelog

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)
v6.9.2 on 11/19/2021
80409 - fix: interface typos (#938)

Released under the MIT License.