Skip to content

useTimeoutFn ​

Category
Export Size
303 B
Last Changed
last week

Wrapper for setTimeout with controls.

Demo ​

Please wait for 3 seconds

Usage ​

js
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 AnyFn>(
  cb: CallbackFn,
  interval: MaybeRefOrGetter<number>,
  options?: UseTimeoutFnOptions,
): Stoppable<Parameters<CallbackFn> | []>

Source ​

Source • Demo • Docs

Contributors ​

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

Changelog ​

v12.0.0-beta.1 on 11/21/2024
0a9ed - feat!: drop Vue 2 support, optimize bundles and clean up (#4349)
v10.0.0-beta.4 on 4/13/2023
4d757 - feat(types)!: rename MaybeComputedRef to MaybeRefOrGetter
0a72b - feat(toValue): rename resolveUnref to toValue
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)

Released under the MIT License.