Loading source
Pulling the file list, source metadata, and syntax-aware rendering for this listing.
Source from repo
Apply VueUse composables in Vue 3/Nuxt projects to replace custom implementations with battle-tested utilities.
Files
Skill
Size
Entrypoint
Format
Open file
Syntax-highlighted preview of this file as included in the skill package.
references/useTimeout.md
1---2category: Animation3---45# useTimeout67Reactive value that becomes `true` after a given time.89## Usage1011```ts12import { useTimeout } from '@vueuse/core'1314const ready = useTimeout(1000)15```1617After 1 second, `ready.value` becomes `true`.1819### With Controls2021```ts22import { useTimeout } from '@vueuse/core'2324const { ready, start, stop, isPending } = useTimeout(1000, { controls: true })2526// Check if timeout is pending27console.log(isPending.value) // true2829// Stop the timeout30stop()3132// Start/restart the timeout33start()34```3536### Options3738| Option | Type | Default | Description |39| ----------- | ------------ | ------- | ------------------------------------------------ |40| `controls` | `boolean` | `false` | Expose `start`, `stop`, and `isPending` controls |41| `immediate` | `boolean` | `true` | Start the timeout immediately |42| `callback` | `() => void` | — | Called when the timeout completes |4344### Callback on Timeout4546```ts47import { useTimeout } from '@vueuse/core'4849useTimeout(1000, {50callback: () => {51console.log('Timeout completed!')52},53})54```5556### Reactive Interval5758The timeout duration can be reactive:5960```ts61import { useTimeout } from '@vueuse/core'6263const duration = ref(1000)64const ready = useTimeout(duration)6566// Change the duration (only affects future timeouts when using controls)67duration.value = 200068```6970## Type Declarations7172```ts73export interface UseTimeoutOptions<74Controls extends boolean,75> extends UseTimeoutFnOptions {76/**77* Expose more controls78*79* @default false80*/81controls?: Controls82/**83* Callback on timeout84*/85callback?: Fn86}87export type UseTimeoutReturn =88| ComputedRef<boolean>89| ({90readonly ready: ComputedRef<boolean>91} & Stoppable)92/**93* @deprecated use UseTimeoutReturn instead94*/95export type UseTimoutReturn = UseTimeoutReturn96/**97* Update value after a given time with controls.98*99* @see {@link https://vueuse.org/useTimeout}100* @param interval101* @param options102*/103export declare function useTimeout(104interval?: MaybeRefOrGetter<number>,105options?: UseTimeoutOptions<false>,106): ComputedRef<boolean>107export declare function useTimeout(108interval: MaybeRefOrGetter<number>,109options: UseTimeoutOptions<true>,110): {111ready: ComputedRef<boolean>112} & Stoppable113```114